I am new to memory management and page replacement algorithms. I found and printed a question about the Least Recently Used algorithm, but unfortunately, I cannot determine if my answer and thought process are correct.
I am trying very hard to solidify my understanding of the algorithm by reading free textbooks and watching examples on YouTube. However, I would greatly appreciate it you could explain if I am grasping the concept, and provide any suggestions of how to improve my answer and correct my thought process.
Please see the image below where the bolded numbers are page faults and the numbers with stars are page hits (I calculated 21 page faults):
P.S. I am sorry if it is difficult to read sideways, but it is the only way I could fit the whole table in the image without having small numbers.
In the case of a page fault LRU (least recently used) looks for that page in the page table which was accessed last and replace it with the new page. In your diagram, I can see a mistake in 6th-page fault when you replace 2 by 1. This is how I think in this algorithm:
Looks for page in the page table (If page hit then move next)
If there is a page fault than find out which page was accessed last in the page table.(It has nothing to do with the last replaced page in the table.)
Taking your case as an example :
So you need replace the 3 with the new page which was accessed last.