1.Easy
What does a hash function do in a hash table?
- ASorts the keys in the table
- BEncrypts the values in the table
- CCounts how many keys are stored
- DMaps a key to an index in the table
2.Easy
What defines a binary tree?
- AEvery node has exactly two children
- BEvery node stores a binary number
- CThe tree has exactly two levels
- DEvery node has at most two children
3.Easy
Which operation is slow in an array but fast at the head of a linked list?
- AFinding the length of a fixed array
- BInserting at the beginning
- CReading the last element by index
- DAccessing the 5th element
4.Medium
AVL trees and red-black trees guarantee:
- AThat keys are stored in insertion order
- BConstant-time search in every case
- CThat no node has two children
- DO(log n) height through rebalancing
5.Medium
What is the time complexity of searching for a key in a balanced binary search tree?
- AO(1)
- BO(log n)
- CO(n log n)
- DO(n)
6.Medium
In a binary min-heap stored in an array (index starting at 0), the children of the node at index i are at:
- Ai + 1 and i + 2
- Bi/2 and i/2 + 1
- C2i + 1 and 2i + 2
- D2i and 2i + 1
7.Hard
Why do databases often use B+ trees rather than plain B-trees for indexes?
- AAll records are in linked leaves, which makes range scans efficient
- BB+ trees store data only in the root
- CB+ trees do not need to be balanced
- DB+ trees use binary internal nodes, which reduces the number of disk reads
8.Hard
A dynamic array doubles when full. Why do many implementations shrink it only when it is one quarter full, not half full?
- ATo keep the array sorted
- BTo avoid repeated resizing when pushes and pops alternate near the boundary
- CBecause the memory allocator can only release memory in quarters of a block
- DBecause halving at one half would lose elements
Answer key
- 1. D · Maps a key to an index in the table
- 2. D · Every node has at most two children
- 3. B · Inserting at the beginning
- 4. D · O(log n) height through rebalancing
- 5. B · O(log n)
- 6. C · 2i + 1 and 2i + 2
- 7. A · All records are in linked leaves, which makes range scans efficient
- 8. B · To avoid repeated resizing when pushes and pops alternate near the boundary
Full step-by-step solutions: practise this topic on examproblems.com.