Optimal Page Replacement Algorithm in C

Here you will get program for optimal page replacement algorithm in C.

Optimal page replacement algorithm says that if page fault occurs then that page should be removed that will not be used for maximum time in future.

It is also known as clairvoyant replacement algorithm or Bélády’s optimal page replacement policy.

Also Read: LRU Page Replacement Algorithm in C

Video Tutorial

Below program shows how to implement this algorithm in C.

Program for Optimal Page Replacement Algorithm in C

Output

Enter number of frames: 3
Enter number of pages: 10
Enter page reference string: 2 3 4 2 1 3 7 5 4 3

2 -1 -1
2 3 -1
2 3 4
2 3 4
1 3 4
1 3 4
7 3 4
5 3 4
5 3 4
5 3 4

Comment below if you have doubts or found anything incorrect in above optimal page replacement algorithm in C.

2 thoughts on “Optimal Page Replacement Algorithm in C

  1. muhammed rishal

    give me simple algorithm for optimal page replacement algorithm

    Reply
  2. jay dave

    it will print wrong output for this
    Enter number of frames: 3
    Enter number of pages: 20
    Enter page reference string: 1 2 3 4 2 5 3 4 2 6 7 8 7 9 7 8 2 5 4 9

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *