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.
Examiner
Design the data structures for an LRU cache supporting get and put in O(1) average time. Explain why both are needed.
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.
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.
You described promotion after access and eviction from the tail.
ImproveSay that eviction also removes the key from the map, preventing a stale entry.
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.
Yours are written from your own notes, and the free plan needs no payment details.
Guides
- How to Study Data Structures and Algorithms EffectivelyA practical method for learning data structures and algorithms through tracing, implementation, complexity analysis and targeted revision.
- Data Structures and Algorithms Study Plan: 8 WeeksAn eight-week data structures and algorithms study plan with timed sessions, coding practice, revision and a way to target weak topics.
- Data Structures and Algorithms Viva Questions: Oral PracticePractise data structures and algorithms viva questions with realistic stations, model answers, follow-up prompts and a structured marking method.
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