1.Easy
The depth of a node in a tree is:
- AThe number of children of that node
- BThe number of edges from that node to the deepest leaf
- CThe number of edges from the root to that node
- DThe number of nodes in its subtree
2.Easy
Which operation is O(1) for an array but O(n) for a singly linked list?
- AAccessing the element at index i
- BInserting at the head
- CReading the first element
- DRemoving the head element
3.Easy
What is the load factor of a hash table?
- AThe time needed to load the table from disk
- BThe number of collisions so far
- CThe number of stored elements divided by the number of buckets
- DThe number of buckets divided by the average length of the keys stored
4.Medium
What happens when a hash table rehashes after its load factor exceeds a threshold?
- AThe existing keys are sorted in place
- BThe oldest keys are deleted to make room
- CA larger table is allocated and every key is inserted again
- DOnly the colliding keys are moved to a new overflow list at the end of the table
5.Medium
Why is traversing an array often much faster in practice than traversing a linked list of the same length?
- AArray elements are contiguous, so they make good use of the CPU cache
- BLinked lists always store elements on disk
- CArray traversal is O(1) in total, while linked list traversal is O(n)
- DArrays use fewer instructions to compare values
6.Medium
Which collision resolution method stores colliding keys in a list at the same bucket?
- ASeparate chaining
- BLinear probing
- CQuadratic probing
- DDouble hashing
7.Hard
The time complexity of decrease-key in a binary heap (given the element's position) is:
- AO(n log n)
- BO(log n)
- CO(n)
- DO(1)
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 2 log2(n + 1)
- BThe height is at most n / 2
- CThe height is exactly log2 n
- DThe height is at most log2 n + 1
Answer key
- 1. C · The number of edges from the root to that node
- 2. A · Accessing the element at index i
- 3. C · The number of stored elements divided by the number of buckets
- 4. C · A larger table is allocated and every key is inserted again
- 5. A · Array elements are contiguous, so they make good use of the CPU cache
- 6. A · Separate chaining
- 7. B · O(log n)
- 8. A · The height is at most 2 log2(n + 1)
Full step-by-step solutions: practise this topic on examproblems.com.