0% found this document useful (0 votes)
40 views2 pages

LRU Algorithm Examples

Uploaded by

Ashmy Shams
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views2 pages

LRU Algorithm Examples

Uploaded by

Ashmy Shams
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Least Recently Used (LRU) Page Replacement

Algorithm - Examples with Answers

Example 1:
Consider a memory with 3 frames. The reference string is: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2. Apply
the LRU page replacement algorithm and calculate the number of page faults.
Step Reference Memory State Page Fault
1 7 [7] Yes
2 0 [7, 0] Yes
3 1 [7, 0, 1] Yes
4 2 [2, 0, 1] Yes
5 0 [2, 0, 1] No
6 3 [3, 0, 1] Yes
7 0 [3, 0, 1] No
8 4 [4, 0, 1] Yes
9 2 [4, 2, 1] Yes
10 3 [3, 2, 1] Yes
11 0 [0, 2, 1] Yes
12 3 [0, 3, 1] Yes
13 2 [0, 3, 2] Yes
Total Page Faults = 10

Example 2:
Consider 4 frames and the reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5. Apply LRU page
replacement and calculate page faults.
Step Reference Memory State Page Fault
1 1 [1] Yes
2 2 [1, 2] Yes
3 3 [1, 2, 3] Yes
4 4 [1, 2, 3, 4] Yes
5 1 [1, 2, 3, 4] No
6 2 [1, 2, 3, 4] No
7 5 [5, 2, 3, 4] Yes
8 1 [5, 1, 3, 4] Yes
9 2 [5, 1, 2, 4] Yes
10 3 [5, 1, 2, 3] Yes
11 4 [4, 1, 2, 3] Yes
12 5 [5, 1, 2, 3] Yes
Total Page Faults = 9

You might also like