A 2014 Alibaba school recruit Pen Test

Source: Internet
Author: User

The problem is that a caching system uses the LRU algorithm, assuming that the cache capacity is 4, and the initial is empty, then in order to access the following data items,

1,5,1,3,5,2,4,1,2

The number of cached direct hits is (), and the data items that are about to be eliminated in the last cache are ().

Let's explain the concept.

LRU (least recently Used) algorithm: It is the most recent use of time from the current time farthest from the data deleted. Concrete implementation Please see this blog "How to implement LRU caching algorithm with Linkedhashmap"

Here's how to solve the problem, we list the state of the cache when accessing data items each time

1
1,5
5,1 hit
5,1,3
1,3,5 hit
1,3,5,2
3,5,2,4 exceeds cache capacity limit, delete 1
5,2,4,1 exceeds cache capacity limit, delete 3
5,4,1,2 hit

So the answer comes out, the direct hit Count is 3, the final cache is ready to be eliminated in the data item is 5


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.