1.Easy
A graph consists of:
- AOnly a root and leaves
- BKeys and hashes only
- CRows and columns
- DVertices (nodes) connected by edges
2.Easy
In a hash table, what is a collision?
- AA key cannot be hashed at all
- BTwo different keys map to the same index
- CTwo equal keys are stored twice
- DThe table runs out of memory
3.Easy
In which order does a postorder traversal of a binary tree visit nodes?
- ARight subtree, then node, then left subtree
- BLeft subtree, then right subtree, then node
- CLeft subtree, then node, then right subtree
- DNode, then left subtree, then right subtree
4.Medium
An adjacency matrix for a graph with V vertices uses how much memory?
- AO(log V)
- BO(V + E)
- CO(E)
- DO(V²)
5.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(n²)
- DO(log n)
6.Medium
Which data structure is used by depth-first search (iterative version)?
- AA stack
- BA queue
- CA heap
- DA hash table only
7.Hard
A segment tree is typically used to:
- AImplement a stack
- BAnswer range queries (such as range sums) and updates in O(log n)
- CSort strings alphabetically by storing each prefix in a separate tree node
- DStore a graph's edges
8.Hard
An object is stored as a key in a hash map, and then a field used by its hash function is changed. What is the likely result?
- AThe map throws an error at the moment the field changes
- BLooking up the object may fail because it sits in the bucket for its old hash
- CThe map automatically moves the key to its new bucket
- DNothing changes, because a key's hash is computed only once when the program starts
Answer key
- 1. D · Vertices (nodes) connected by edges
- 2. B · Two different keys map to the same index
- 3. B · Left subtree, then right subtree, then node
- 4. D · O(V²)
- 5. B · O(1)
- 6. A · A stack
- 7. B · Answer range queries (such as range sums) and updates in O(log n)
- 8. B · Looking up the object may fail because it sits in the bucket for its old hash
Full step-by-step solutions: practise this topic on examproblems.com.