1.Easy
The depth of a node in a tree is:
- AThe number of children of that node
- BThe number of nodes in its subtree
- CThe number of edges from that node to the deepest leaf
- DThe number of edges from the root to that node
2.Easy
In which order does a preorder traversal of a binary tree visit nodes?
- ALevel by level from the top
- BNode, then left subtree, then right subtree
- CLeft subtree, then right subtree, then node
- DLeft subtree, then node, then right subtree
3.Easy
What defines a binary tree?
- AThe tree has exactly two levels
- BEvery node has exactly two children
- CEvery node has at most two children
- DEvery node stores a binary number
4.Medium
What is true of the adjacency matrix of an undirected graph?
- AIt is always upper triangular
- BEach row has exactly one 1
- CIts main diagonal always contains ones
- DIt is symmetric about the main diagonal
5.Medium
What is the cost of inserting an element in the middle of an array of n elements?
- AO(n), because later elements must shift
- BO(log n), because of binary search
- CO(1), because the index is known
- DO(n²), because each element moves n times
6.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(1)
- BO(log n)
- CO(n)
- DO(n²)
7.Hard
Why can elements not simply be deleted from a standard Bloom filter by clearing their bits?
- ABits in a Bloom filter cannot be changed after creation
- BThose bits may also belong to other elements, which would cause false negatives
- CDeleting would increase the false positive rate to 100%
- DBloom filters store the full elements, and these cannot be located again once hashed
8.Hard
Which data structure supports an LRU (least recently used) cache with O(1) get and put?
- AA binary search tree only
- BA hash map combined with a doubly linked list
- CA stack only
- DA single sorted array
Answer key
- 1. D · The number of edges from the root to that node
- 2. B · Node, then left subtree, then right subtree
- 3. C · Every node has at most two children
- 4. D · It is symmetric about the main diagonal
- 5. A · O(n), because later elements must shift
- 6. A · O(1)
- 7. B · Those bits may also belong to other elements, which would cause false negatives
- 8. B · A hash map combined with a doubly linked list
Full step-by-step solutions: practise this topic on examproblems.com.