1.Easy
What is the name of the stack operation that adds an element to the top?
- APush
- BPeek
- CPop
- DEnqueue
2.Easy
In a graph, what is a cycle?
- AA path that starts and ends at the same vertex
- BAn edge with a weight of zero
- CA path that visits every vertex
- DA vertex with no edges
3.Easy
In a hash table, what is a collision?
- AThe table runs out of memory
- BTwo different keys map to the same index
- CTwo equal keys are stored twice
- DA key cannot be hashed at all
4.Medium
A queue is implemented with two stacks: push onto an "in" stack, and pop from an "out" stack, refilling it from "in" when empty. What is the amortised cost per operation?
- AO(n²)
- BO(1)
- CO(log n)
- DO(n)
5.Medium
Why is traversing an array often much faster in practice than traversing a linked list of the same length?
- AArray elements are contiguous, so they make good use of the CPU cache
- BLinked lists always store elements on disk
- CArrays use fewer instructions to compare values
- DArray traversal is O(1) in total, while linked list traversal is O(n)
6.Medium
A node in a binary search tree has a right subtree. Where is its in-order successor?
- AIts parent, always
- BIts right child, always
- CThe rightmost node of its left subtree
- DThe leftmost node of its right subtree
7.Hard
Why might a server choose its hash function at random from a universal family?
- ATo guarantee that no two keys can ever collide, whatever keys an attacker sends
- BTo remove the need to resize the table
- CTo make the hash table sorted
- DTo make it very unlikely that an attacker can pick many keys that all collide
8.Hard
Inserting a key into an AVL tree makes a node's left subtree too tall, and the new key went into the left subtree of its left child (left-left case). Which fix is applied?
- AA left rotation at the child, then a right rotation at the node
- BA single right rotation at the unbalanced node
- CRecolouring the node and its child
- DA single left rotation at the unbalanced node
Answer key
- 1. A · Push
- 2. A · A path that starts and ends at the same vertex
- 3. B · Two different keys map to the same index
- 4. B · O(1)
- 5. A · Array elements are contiguous, so they make good use of the CPU cache
- 6. D · The leftmost node of its right subtree
- 7. D · To make it very unlikely that an attacker can pick many keys that all collide
- 8. B · A single right rotation at the unbalanced node
Full step-by-step solutions: practise this topic on examproblems.com.