1.Easy
Which data structure works on the principle "last in, first out"?
- AHash table
- BStack
- CQueue
- DLinked list
2.Easy
What does the peek (or top) operation on a stack do?
- AReturns the top element without removing it
- BRemoves the top element and returns it
- CRemoves all elements from the stack
- DReturns the bottom element of the stack
3.Easy
What does a hash function do in a hash table?
- ASorts the keys in the table
- BCounts how many keys are stored
- CMaps a key to an index in the table
- DEncrypts the values in the table
4.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
- B2i + 1 and 2i + 2
- C2i and 2i + 1
- Di/2 and i/2 + 1
5.Medium
How does extract-min work in a binary min-heap?
- ARemove the root and shift all elements one place left
- BMove the last element to the root and sift it down
- CSearch all leaves for the new minimum
- DRemove the last element of the array
6.Medium
How is a new element inserted into a binary heap?
- AInsert it at its sorted position by shifting all of the larger elements one place right
- BPlace it at the end of the array and sift it up while it violates the heap property
- CRebuild the whole heap from scratch
- DPlace it at the root and sift it down
7.Hard
What does a splay tree do after each access?
- ARecolours the nodes on the search path
- BMoves the accessed node to a leaf
- CRotates the accessed node up to the root
- DRebuilds the whole tree in balanced form
8.Hard
What guarantee do the red-black tree rules give about the height of a tree with n keys?
- AThe height is at most log2 n + 1
- BThe height is at most 2 log2(n + 1)
- CThe height is at most n / 2
- DThe height is exactly log2 n
Answer key
- 1. B · Stack
- 2. A · Returns the top element without removing it
- 3. C · Maps a key to an index in the table
- 4. B · 2i + 1 and 2i + 2
- 5. B · Move the last element to the root and sift it down
- 6. B · Place it at the end of the array and sift it up while it violates the heap property
- 7. C · Rotates the accessed node up to the root
- 8. B · The height is at most 2 log2(n + 1)
Full step-by-step solutions: practise this topic on examproblems.com.