Question: Level 2 (45%) acces a duba bern in the cache. The get/lipy function retricwes the vilue of the data item eiven by the key parameter

 Level 2 (45\%) acces a duba bern in the cache. Theget/lipy function retricwes the vilue of the data item eiven by the

Level 2 (45\%) acces a duba bern in the cache. The get/lipy function retricwes the vilue of the data item eiven by the key parameter it the key edists in the cache. The pudkry, valupy function mad fe: the walue of the duta bem, if the key exith, or inierts a mow data item, if the bey does nat. sinite. The erdering of dita bers in the cache mut mitarm to the deweriptian in the bem in the mat recently uied. Cvery time a data ben in acreued, whether using get or pot the data item has bo be msed is the end (rightmest) af the cache is beceme the moe! recently uied item. When a new duta item in inierted is a full cuche, the least recently abes (lettrout) iten nends to be evicted Fer exmple, gim a cuche of capaciby E: [12,' DSO], [2,200], [1, ]00], [4, 400], the cache conbenti will be updated an follown. 1. pertay [11,200][2,2001,14,600],[1,200] 4. puthoo, 5][1,4,60],[1,2001,[2,6],[10,1],[200,5] In addidion to the inputs you neceind tren level 2, you will ahs receive a lite at the put eperation with bey kIV and walue weuc. Get operition prints the walue of the key: walue pure if the bey eakat, otherwile prints "WUI.". Fut eperatian dees not need is prin. anything. The cemmund "ing inputa: 1. Capucity of the cache C ointegari, C=1 mane that the cache hat urlimined capuch. A utring of integral keys k2,k2,,Ka weparated by, when Nb is number of key. 4. A weries af commands conabding of either "get, iry" er "put,kre, walec" wepurated by a newine character. 5. The input nutt be ended with "md"- 3 chGcia3s Computer Pnegramning 1 Ausignent 1 Dupputs: 1. Wamine meuage if N2=Nt. 2. Fer every eet eperation, print the value of the kry-alue pair if the kry excth otherwilie print "Wuc.". bem beine the leat necently uied while the lat irightiment] ten being the moes recontly uned. Ausumptian: * 1c1000 ar c=1 * 1N2,N01000 - input keys can be monerted to integers - Input keys are aniquet, me duplicates - Ingut valuen are nen-null utring. * None of the valum will be equal to 'MuL' ENGG1330 Computer Programming I Assignment 1 ENGG1330 Computer Programming I (22-23 Sem 2) Assignment 1 Least Recently Used (LRU) Cache Due date: noon, 17-MAR-2023 (Friday) Late submission: 20% deduction per day Coverage: Only Python libraries/features covered in this course up to and including Array (List). Using other libraries, non-built-in functions, and features (e.g., dictionary, set) is not allowed and you will be given zero marks. If you are unsure, feel free to contact us for clarification. Grading: Evaluated against a set of private test cases on VPLs. While programming style is not graded, you are highly recommended to use function to factor your program and write clear and tidy codes, e.g., appropriate comments, concise and clear naming, appropriate spacing. Introduction You are having a technical interview for a software engineer internship at EEE Limited. You are asked to implement a least recently used (LRU) cache in Python. The interviewers know that you may be unfamiliar with LRU cache, so they also give you a description of LRU cache as follows. A cache in programming is used to store data so that future requests for the data can be served faster. A data item in cache is stored as a key-value pair [key, value], where key is a unique identifier that identifies the data item and value is the data item to be stored. For example, after computing total marks of students, a cache can be used to store the total marks by using student ID as the key and his/her total mark as the value. As a result, a request for a student's total mark can be directly retrieved from the cache instead of re-computing it to reduce the computational time. However, since the cache also occupies storage/memory, its capacity is limited. When the cache is full, an existing item must be swapped out when a new item needs to be stored. A LRU cache is a special kind of cache that defines the way of evicting item from the cache when it is full. Its policy is to evict the least recently used item. For example, a cache having capacity of 4 and is currently storing [[1, '101'], [2, '102'], [3, '103'], [4, '104']], where the 1st (leftmost) item [1, "101'] is the least recently used and the last (rightmost) item [4, '104'] is the most recently used. When the item [2, '102'] is accessed, the cache becomes [[1, '101'], [3, '103'], [4, '104'], [2, '102']] as the item [2, '102'] becomes the most recently used. When another item [10, '110'] is pushed into the cache, the cache cannot hold all of the items and must evict the least recently used item which is [1, '101'] and the cache becomes [[3, '103'], [4, '104'], [2, '102'], [10, '110']]. Level 2 (45\%) acces a duba bern in the cache. The get/lipy function retricwes the vilue of the data item eiven by the key parameter it the key edists in the cache. The pudkry, valupy function mad fe: the walue of the duta bem, if the key exith, or inierts a mow data item, if the bey does nat. sinite. The erdering of dita bers in the cache mut mitarm to the deweriptian in the bem in the mat recently uied. Cvery time a data ben in acreued, whether using get or pot the data item has bo be msed is the end (rightmest) af the cache is beceme the moe! recently uied item. When a new duta item in inierted is a full cuche, the least recently abes (lettrout) iten nends to be evicted Fer exmple, gim a cuche of capaciby E: [12,' DSO], [2,200], [1, ]00], [4, 400], the cache conbenti will be updated an follown. 1. pertay [11,200][2,2001,14,600],[1,200] 4. puthoo, 5][1,4,60],[1,2001,[2,6],[10,1],[200,5] In addidion to the inputs you neceind tren level 2, you will ahs receive a lite at the put eperation with bey kIV and walue weuc. Get operition prints the walue of the key: walue pure if the bey eakat, otherwile prints "WUI.". Fut eperatian dees not need is prin. anything. The cemmund "ing inputa: 1. Capucity of the cache C ointegari, C=1 mane that the cache hat urlimined capuch. A utring of integral keys k2,k2,,Ka weparated by, when Nb is number of key. 4. A weries af commands conabding of either "get, iry" er "put,kre, walec" wepurated by a newine character. 5. The input nutt be ended with "md"- 3 chGcia3s Computer Pnegramning 1 Ausignent 1 Dupputs: 1. Wamine meuage if N2=Nt. 2. Fer every eet eperation, print the value of the kry-alue pair if the kry excth otherwilie print "Wuc.". bem beine the leat necently uied while the lat irightiment] ten being the moes recontly uned. Ausumptian: * 1c1000 ar c=1 * 1N2,N01000 - input keys can be monerted to integers - Input keys are aniquet, me duplicates - Ingut valuen are nen-null utring. * None of the valum will be equal to 'MuL' ENGG1330 Computer Programming I Assignment 1 ENGG1330 Computer Programming I (22-23 Sem 2) Assignment 1 Least Recently Used (LRU) Cache Due date: noon, 17-MAR-2023 (Friday) Late submission: 20% deduction per day Coverage: Only Python libraries/features covered in this course up to and including Array (List). Using other libraries, non-built-in functions, and features (e.g., dictionary, set) is not allowed and you will be given zero marks. If you are unsure, feel free to contact us for clarification. Grading: Evaluated against a set of private test cases on VPLs. While programming style is not graded, you are highly recommended to use function to factor your program and write clear and tidy codes, e.g., appropriate comments, concise and clear naming, appropriate spacing. Introduction You are having a technical interview for a software engineer internship at EEE Limited. You are asked to implement a least recently used (LRU) cache in Python. The interviewers know that you may be unfamiliar with LRU cache, so they also give you a description of LRU cache as follows. A cache in programming is used to store data so that future requests for the data can be served faster. A data item in cache is stored as a key-value pair [key, value], where key is a unique identifier that identifies the data item and value is the data item to be stored. For example, after computing total marks of students, a cache can be used to store the total marks by using student ID as the key and his/her total mark as the value. As a result, a request for a student's total mark can be directly retrieved from the cache instead of re-computing it to reduce the computational time. However, since the cache also occupies storage/memory, its capacity is limited. When the cache is full, an existing item must be swapped out when a new item needs to be stored. A LRU cache is a special kind of cache that defines the way of evicting item from the cache when it is full. Its policy is to evict the least recently used item. For example, a cache having capacity of 4 and is currently storing [[1, '101'], [2, '102'], [3, '103'], [4, '104']], where the 1st (leftmost) item [1, "101'] is the least recently used and the last (rightmost) item [4, '104'] is the most recently used. When the item [2, '102'] is accessed, the cache becomes [[1, '101'], [3, '103'], [4, '104'], [2, '102']] as the item [2, '102'] becomes the most recently used. When another item [10, '110'] is pushed into the cache, the cache cannot hold all of the items and must evict the least recently used item which is [1, '101'] and the cache becomes [[3, '103'], [4, '104'], [2, '102'], [10, '110']]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!