Study guides

Data Structures and Algorithms

3 guides for this subject — how to prepare, what to practise, and how to know it has gone in.

A spoken answer, marked

An examiner's question, answered out loud and marked criterion by criterion. From Data Structures and Algorithms Viva Questions: Oral Practice.

Oral — Choosing a structure for an LRU cacheMarked

Examiner

Design the data structures for an LRU cache supporting get and put in O(1) average time. Explain why both are needed.

2:313:00Mark answer
78%Choosing a structure for an LRU cache — marked78/100 · Sound, with one implementation gap · 2:31 spoken of 3:00
Correct data-structure choice17/20

You chose a hash map and doubly linked list and explained the separate jobs they perform.

ImproveState explicitly that each map value points to its list node.

Complexity reasoning15/20

You gave O(1) average time for get and put and linked this to direct lookup and splicing.

ImproveMention the hash-table assumption and distinguish average from worst-case lookup.

Operational completeness16/20

You described promotion after access and eviction from the tail.

ImproveSay that eviction also removes the key from the map, preventing a stale entry.

Clarity and boundary cases13/20

The explanation was ordered, but capacity one and updating an existing key were not addressed.

ImproveAdd one sentence covering an existing key and the smallest valid capacity.

A strong answerUse a hash map from each key to its node in a doubly linked list. The list is ordered from most recently used at the front to least recently used at the back, so a hit can be moved and the tail can be evicted in O(1) time. The map provides average O(1) access to the node, while the list provides constant-time removal and insertion. On eviction, remove the tail node from both the list and the map; updating an existing key also moves its node to the front.

Start studying data structures and algorithms

Yours are written from your own notes, and the free plan needs no payment details.

Guides

Studying data structures and algorithms? Build your data structures and algorithms board from your own notes — the cards, papers and lectures are written from it. Free plan: 20 cards, a paper, a lecture and a viva to try.

Start on MySummaries

Other subjects