1.Easy
In an undirected graph, what is the degree of a vertex?
- AIts position in the adjacency list
- BThe length of the longest path from it
- CThe number of edges connected to it
- DThe number of vertices in the graph
2.Easy
Which operation is O(1) for an array but O(n) for a singly linked list?
- ARemoving the head element
- BAccessing the element at index i
- CInserting at the head
- DReading the first element
3.Easy
Which data structure is most suitable for the "undo" feature in a text editor?
- AStack
- BHash set
- CGraph
- DQueue
4.Medium
How is a new element inserted into a binary heap?
- APlace it at the root and sift it down
- BRebuild the whole heap from scratch
- CPlace it at the end of the array and sift it up while it violates the heap property
- DInsert it at its sorted position by shifting all of the larger elements one place right
5.Medium
How many nodes does a perfect binary tree of height h have, with height counted in edges?
- Ah2
- B2h + 1
- C2h+1 − 1
- D2h
6.Medium
A binary tree has root 1 with left child 2 and right child 3; node 2 has children 4 (left) and 5 (right). What is the preorder traversal?
- A4 5 2 3 1
- B1 2 3 4 5
- C4 2 5 1 3
- D1 2 4 5 3
7.Hard
What guarantee do the red-black tree rules give about the height of a tree with n keys?
- AThe height is at most n / 2
- BThe height is at most 2 log2(n + 1)
- CThe height is at most log2 n + 1
- DThe height is exactly log2 n
8.Hard
Which statement about heapsort is correct?
- AIt runs in O(n) time on any input
- BIt needs a binary search tree as extra storage, so it uses O(n) extra memory
- CIt sorts in place in O(n log n) worst-case time but is not stable
- DIt is stable and needs O(n) extra memory
Answer key
- 1. C · The number of edges connected to it
- 2. B · Accessing the element at index i
- 3. A · Stack
- 4. C · Place it at the end of the array and sift it up while it violates the heap property
- 5. C · 2h+1 − 1
- 6. D · 1 2 4 5 3
- 7. B · The height is at most 2 log2(n + 1)
- 8. C · It sorts in place in O(n log n) worst-case time but is not stable
Full step-by-step solutions: practise this topic on examproblems.com.