1.Easy
What does a hash function do in a hash table?
- ACounts how many keys are stored
- BEncrypts the values in the table
- CMaps a key to an index in the table
- DSorts the keys in the table
2.Easy
How many edges does a tree with n nodes have?
- An + 1
- Bn
- Cn − 1
- D2n
3.Easy
In which order does a preorder traversal of a binary tree visit nodes?
- ALeft subtree, then node, then right subtree
- BNode, then left subtree, then right subtree
- CLevel by level from the top
- DLeft subtree, then right subtree, then node
4.Medium
In a binary heap stored in an array starting at index 0, where is the parent of the node at index i?
- AAt index ⌊i / 2⌋ + 1
- BAt index i − 1
- CAt index 2i + 1
- DAt index ⌊(i − 1) / 2⌋
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
AVL trees and red-black trees guarantee:
- AO(log n) height through rebalancing
- BThat keys are stored in insertion order
- CConstant-time search in every case
- DThat no node has two children
7.Hard
A Bloom filter can answer "is this element in the set?" with:
- AExact answers always
- BPossible false positives but no false negatives
- CAnswers only for numbers
- DPossible false negatives but no false positives
8.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 make it very unlikely that an attacker can pick many keys that all collide
- CTo remove the need to resize the table
- DTo make the hash table sorted
Answer key
- 1. C · Maps a key to an index in the table
- 2. C · n − 1
- 3. B · Node, then left subtree, then right subtree
- 4. D · At index ⌊(i − 1) / 2⌋
- 5. A · O(n), because later elements must shift
- 6. A · O(log n) height through rebalancing
- 7. B · Possible false positives but no false negatives
- 8. B · To make it very unlikely that an attacker can pick many keys that all collide
Full step-by-step solutions: practise this topic on examproblems.com.