FOR FREE MATERIALS

UGC NET question on Optimal algorithm

 

Q. NET 2014-July-Q33 

Consider a program that consists of 8 pages (from 0 to 7) and we have 4 page frames in the physical memory for the pages. The page reference string is:

 

1  2  3  2  5  6  3  4  6  3  7  3  1  5  3  6  3  4  2  4  3  4  5  1 

 

The number of page faults in LRU and optimal page replacement algorithms are respectively (without including initial page faults to fill available page frames with pages):

 

(A) 9 and 6               (B) 10 and 7 

(C) 9 and 7               (D) 10 and 6

 

In this question we only solve with optimal policy, later on, we will solve it by LRU also.

 

You should know:

Before seeing the solution please follow the previous chapter: 

Optimal Page Replacement algorithm

 

Solution:

As per questions we have 8 pages (0-7) so, all page references between 0 to 7. 

 

1  2 3  2  5 6  3  4 6  3  7 3  1  5 3  6  3 4  2  4 3  4  5  1 

 

Now the number of frames given is 4.

 

So, the number of page faults is 11 but as per the question, we are not including initial page faults to fill available page frames with pages.

 

Now, now available frames initially 4 and first 4 page references which are filled up vacant frames are 1, 2, 3, 5 (see first frames in the above picture)

 

So, final number of page fault 11 – 4 = 7

 

Shortcut method:

But in examination it is not possible to solve it by this elaborative way we can do it by a single frame like below:

Page references: 1 2  3  2 5  6  3 4  6  3 7  3  1 5  3  6 3  4  2 4  3  4 5  1 

 

 

The above process is a shortcut and the easiest process to calculate page faults.

So, the number of page faults is 7.

 

To know more about how the page is replacing here by optimal page replacement policy please follow the previous chapter: Optimal Page Replacement algorithm.