How to use viva questions for data structures and algorithms

A viva in data structures and algorithms tests more than whether you can recite a definition. You may be asked to choose a data structure, justify an algorithm, state its complexity, trace it on an example, and explain what changes when an assumption is removed.

There is no single international format for a data structures and algorithms viva. Your university or professional course may use short questions, a whiteboard discussion, code tracing, or a longer problem-solving conversation. Check the official course handbook or assessment guide for the exact duration, permitted materials and marking scheme.

The safest preparation method is to practise answers in layers:

  1. Give the direct answer. State the data structure, algorithm or complexity.
  2. Justify it. Explain the invariant, operation or design choice that makes it suitable.
  3. Test the boundary. Mention an empty input, duplicate value, worst case or invalid operation where relevant.
  4. Compare alternatives. Say when another approach would be preferable.
  5. Use a small example. Trace enough steps for the examiner to see that you understand the mechanism.

Do not treat complexity as a label to memorise separately from the algorithm. In a viva, “binary search is O(log n)” is incomplete if you cannot explain that the search interval is halved after each comparison and that the input must be sorted.

A viva map for the subject

The main areas worth covering are:

  • arrays, linked lists, stacks, queues and hash tables;
  • trees, binary search trees, heaps and balanced trees;
  • graphs, representations, breadth-first search and depth-first search;
  • sorting and searching, including stability and in-place behaviour;
  • recursion, divide and conquer, greedy algorithms and dynamic programming;
  • asymptotic analysis, correctness arguments and trade-offs between time and space.

A useful revision board links each topic to operations and decisions. For example, a queue is not just “first in, first out”: you should be able to explain an array implementation, a circular buffer, the cost of enqueue and dequeue, and why a linked implementation behaves differently.

A board on this topic ends up looking like this:

Data Structures and Algorithms Core structures and algorithm choicesStudy
Core structures and algorithm choices5 sections · 3 columns
Complexity and proof4 due
  • Binary search halves a sorted search interval: O(log n) comparisons.
  • Amortised array append is O(1) when capacity doubles, although one resize costs O(n).
  • For a loop nest, multiply independent iteration counts; for sequential blocks, retain the dominant term.
Graphs3 due
  • BFS uses a queue and finds shortest edge-count paths in an unweighted graph.
  • DFS uses a stack or recursion and supports cycle and reachability analysis.
  • An adjacency matrix uses O(V²) space; an adjacency list uses O(V + E) space.
Linear structures
  • A stack supports push and pop at one end: LIFO; each is O(1).
  • A queue supports enqueue at the rear and dequeue at the front: FIFO.
  • A doubly linked list deletes a node in O(1) when the node reference is already known; finding it is O(n).
Sorting and design

Merge sort is O(n log n) in the worst case and is stable with the usual merge. Quicksort has expected O(n log n) time but O(n²) worst-case time with poor pivots. Dynamic programming stores results for overlapping subproblems; divide and conquer generally creates independent subproblems.

Trees and heaps
StructureKey propertyTypical operation
BSTleft keys < node < right keysSearch O(h)
Min-heapparent key ≤ child keysExtract-min O(log n)
AVL treebalance factor −1, 0 or 1Search O(log n)

Use the board to identify facts that need exact recall and concepts that need spoken explanation. Exact recall includes the AVL balance condition, heap operation costs and graph space requirements. Explanation practice includes why BFS gives shortest unweighted paths and why a hash table can degrade to O(n).

A checklist for complete answers

Before sitting a station, turn the topic into a short “must say” checklist. This prevents a fluent but incomplete answer. For a question about choosing a structure, the checklist might include the required operations, expected complexity, ordering requirements, memory overhead and failure cases.

The core checklist for this board is compact enough to use before each practice session:

What to coverCore structures and algorithm choices
Binary search requires sorted data and runs in O(log n) comparisons; a linear scan is O(n) but needs no ordering.
A hash table has expected O(1) lookup with a suitable hash function and controlled load factor, but O(n) worst-case lookup under severe collisions.
BFS gives shortest paths by number of edges in an unweighted graph; Dijkstra is appropriate for non-negative weighted edges.
A min-heap gives O(1) access to the minimum, O(log n) insertion and O(log n) extraction; it is not fully sorted.
Dynamic programming needs subproblem overlap and optimal substructure; memoisation is top-down, tabulation is bottom-up.

For each item, practise one sentence of definition, one sentence of justification and one example. If the examiner asks a follow-up, extend the answer rather than restarting it from the beginning.

Five stations worth practising

These stations cover the kinds of decisions that expose whether you understand the subject rather than merely remembering vocabulary. The opening questions are deliberately broad. A real examiner can then probe complexity, assumptions, implementation details or correctness.

The station list below gives you a route through the oral tab: three stations are ready to attempt, while the others can be added after you revise their linked board sections.

The station list looks like this:

StationAttemptsBestAvg
Choosing a structure for an LRU cacheDesign the data structures for an LRU cache supporting get and put in O(1) average time. Explain why both are needed.37972
BFS, DFS and shortest pathsExplain how you would find the shortest path in an unweighted graph, and justify your choice of traversal.28476
Hash table collision handlingExplain what happens when two keys receive the same hash-table index, and compare two collision-resolution methods.0
Quicksort and worst-case behaviourGive the time and space complexity of quicksort and explain how pivot selection affects the worst case.16868
Dynamic programming formulationTurn a recursive optimisation problem into a dynamic-programming solution. What properties must the problem have first?0

Station 1: choosing a structure for an LRU cache

The key is to connect the required operations to the representation. A hash map alone gives fast lookup but does not maintain recency order. A linked list alone can maintain order but takes linear time to find a requested key.

A strong answer should state that the cache uses a hash map from key to linked-list node, plus a doubly linked list ordered from most recently used to least recently used. On a successful get, remove the node and move it to the front. On put, update and move an existing node, or insert a new node at the front; if the capacity is exceeded, remove the tail node and delete its map entry. With direct node references and constant-time list splicing, the average operation is O(1), subject to the usual hash-table assumption.

The recorded attempt below is good but misses one implementation condition: list operations must be constant time because the map stores the node itself, not merely its key.

A marked oral answer on this station looks like this:

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.

Notice the difference between naming two structures and explaining their division of labour. The latter is what makes the answer defensible when the examiner asks, “Why not use just a linked list?”

Station 2: BFS, DFS and shortest paths

This question tests whether you can match an algorithm to the graph model. The important qualification is “shortest” by number of edges in an unweighted graph. If edges carry non-negative weights, breadth-first search is no longer sufficient; Dijkstra’s algorithm is the usual alternative.

A candidate should describe a queue, a visited set and a predecessor array or map. Mark a vertex when it is enqueued, then process its neighbours. Because vertices are discovered layer by layer, the first discovery gives a path with the minimum number of edges. With an adjacency list, the time is O(V + E) and the extra space is O(V).

The attempt below explains the central idea but loses marks by marking vertices too late. That can enqueue the same vertex repeatedly and makes the implementation less efficient.

A second marked attempt is shown here:

Oral — BFS, DFS and shortest pathsMarked

Examiner

Explain how you would find the shortest path in an unweighted graph, and justify your choice of traversal.

1:482:30Mark answer
84%BFS, DFS and shortest paths — marked84/100 · Competitive · 1:48 spoken of 2:30
Algorithm selection and justification18/20

You selected BFS and correctly tied it to minimum edge count in an unweighted graph.

ImproveAdd that weighted non-negative edges require a different method such as Dijkstra’s algorithm.

Correct procedure17/20

You used a queue and predecessor links to reconstruct the path.

ImproveMark a vertex visited when enqueuing it, not when removing it from the queue.

Complexity reasoning17/20

You gave O(V + E) for an adjacency-list graph and explained that each edge is examined.

ImproveState the corresponding O(V²) behaviour if an adjacency matrix is scanned for neighbours.

Communication and edge cases15/20

The answer was concise and included an unreachable target.

ImproveMention the source-equals-target case and that no path is returned when the queue empties.

A strong answerFor an unweighted graph, I would use BFS from the source. I mark the source visited, put it in a queue, and when I discover an unvisited neighbour I mark it immediately, record its predecessor and enqueue it. BFS processes vertices by distance from the source, so the first time I reach the target I have a path with the fewest edges. With adjacency lists the time is O(V + E) and the space is O(V); for non-negative weighted edges I would consider Dijkstra’s algorithm instead.

When practising, force yourself to state what “shortest” means. This single word changes the algorithm choice. Also distinguish reachability from path reconstruction: a visited set answers whether a vertex was reached, while predecessor links let you produce the route.

Station 3: hash-table collision handling

A collision occurs when distinct keys map to the same slot. It is not evidence that the hash function has failed; collision handling is part of the table design. You should be able to compare separate chaining with open addressing.

In separate chaining, each slot refers to a collection such as a linked list or dynamic array of entries. In open addressing, every entry stays in the table and the implementation probes alternative slots, for example by linear probing or double hashing. Linear probing is simple and cache-friendly but can suffer primary clustering. Deletion needs care: in an open-addressed table, clearing a slot can break later searches, so a tombstone or cluster repair is needed.

The third station shows a candidate who knows the methods but does not connect load factor to performance.

A third marked answer is as follows:

Oral — Hash table collision handlingMarked

Examiner

Explain what happens when two keys receive the same hash-table index, and compare two collision-resolution methods.

2:062:45Mark answer
76%Hash table collision handling — marked76/100 · Adequate, but performance needs qualification · 2:06 spoken of 2:45
Conceptual accuracy16/20

You correctly defined a collision and described chaining and open addressing.

ImproveMake clear that the hash index is only an initial position; the second key is not discarded.

Comparison of methods15/20

You identified extra per-slot storage for chaining and probing for open addressing.

ImproveInclude one concrete disadvantage: clustering for linear probing or deletion complexity for open addressing.

Complexity and assumptions13/20

You stated expected O(1) lookup.

ImproveTie expected performance to a suitable hash function and a controlled load factor, then give O(n) as a possible worst case.

Practical judgement15/20

You recognised that the choice depends on memory and implementation constraints.

ImproveMention cache locality for open addressing or simpler deletion for chaining.

A strong answerWhen two distinct keys have the same initial index, the table uses its collision policy to store and find both entries. With separate chaining, a slot holds a collection of entries; with open addressing, the table probes other slots, such as by linear probing or double hashing. Expected lookup can be O(1) when the hash function distributes keys well and the load factor is controlled, but the worst case is O(n). Open addressing uses contiguous table storage and can have good cache behaviour, while chaining usually makes deletion more straightforward.

For this station, practise comparing methods rather than listing them. An examiner can ask, “Which would you choose?” A suitable answer depends on the workload: deletion requirements, memory overhead, cache behaviour, expected load and whether resizing is acceptable.

Improve an answer without memorising a script

After each station, listen for four gaps:

  • a missing precondition, such as sorted input for binary search;
  • a missing invariant, such as the heap parent being no greater than its children;
  • a complexity claim without a reason;
  • a boundary case, such as an empty graph, duplicate key or unreachable target.

Do not memorise the model answers word for word. Instead, use them to build a compact answer skeleton. Then repeat the station with a changed condition: weighted rather than unweighted edges, a full hash table, a duplicate BST key, or a graph containing a cycle.

One transcript review might identify this specific wording problem:

Transcript

I would use BFS because it checks the nearest vertices first. Then I would mark a vertex when I remove it from the queue. I would store the path as I go. The complexity is O(V plus E) with a list.

not enough detail
Then I would mark a vertex when I remove it from the queue

Marking on removal can enqueue the same vertex several times when two current vertices point to it. You also need to say what path information is stored and why the complexity follows from scanning vertices and edges.

Say: Mark a neighbour as visited when you enqueue it, record its predecessor at that moment, and explain that each vertex and adjacency-list edge is processed at most once.

The correction is not a longer definition. It is a precise implementation decision followed by its consequence. That is the level of detail most follow-up questions are looking for.

A short examiner-style debrief can also help you practise emphasis and pacing:

Spoken feedback

You selected BFS correctly, but listen for the condition you must say aloud: shortest means fewest edges in an unweighted graph. Without that qualification, your answer sounds broader than it is.

How MySummaries helps

Build a revision board from your lecture slides, notes and worked examples, then use its oral stations to practise the exact decisions and explanations in this subject. The platform can record an answer, mark it against criteria such as algorithm selection, correctness, complexity reasoning and handling of edge cases, and return missed points to your revision work. Its audio lectures can then turn a weak section such as collision handling or dynamic programming into a short spoken recap.

Start with MySummaries and organise your own data structures and algorithms material into boards before choosing the stations to practise.