1.Easy
What is the root of a tree?
- AThe top node with no parent
- BA node with no children
- CAny node in the middle
- DThe node with the largest value
2.Easy
Which operation is O(1) for an array but O(n) for a singly linked list?
- AInserting at the head
- BReading the first element
- CRemoving the head element
- DAccessing the element at index i
3.Easy
Which data structure is used to perform a level-order traversal of a tree?
- AQueue
- BStack
- CHash table
- DPriority queue
4.Medium
A trie (prefix tree) is especially efficient for:
- AStoring matrices
- BSorting numbers
- CPrefix searches such as autocomplete
- DFinding shortest paths
5.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 − 1
- BAt index 2i + 1
- CAt index ⌊(i − 1) / 2⌋
- DAt index ⌊i / 2⌋ + 1
6.Medium
What is the cost of inserting an element in the middle of an array of n elements?
- AO(n²), because each element moves n times
- BO(1), because the index is known
- CO(n), because later elements must shift
- DO(log n), because of binary search
7.Hard
In Kruskal's minimum spanning tree algorithm, what is the union-find structure used for?
- AChoosing the starting vertex
- BSorting the edges by weight
- CStoring each vertex's current distance from the source during the search
- DChecking whether an edge's two endpoints are already connected
8.Hard
An AVL node is unbalanced because its left child's right subtree became too tall (left-right case). Which fix is applied?
- AA right rotation at the left child, then a left rotation at the node
- BA single left rotation at the node
- CA single right rotation at the node
- DA left rotation at the left child, then a right rotation at the node
Answer key
- 1. A · The top node with no parent
- 2. D · Accessing the element at index i
- 3. A · Queue
- 4. C · Prefix searches such as autocomplete
- 5. C · At index ⌊(i − 1) / 2⌋
- 6. C · O(n), because later elements must shift
- 7. D · Checking whether an edge's two endpoints are already connected
- 8. D · A left rotation at the left child, then a right rotation at the node
Full step-by-step solutions: practise this topic on examproblems.com.