1.Easy
Which data structure is most suitable for the "undo" feature in a text editor?
- AStack
- BQueue
- CHash set
- DGraph
2.Easy
What is a weighted graph?
- AA graph with more edges than vertices
- BA graph in which some vertices are heavier than others because they have more edges
- CA graph in which each edge has a numeric value such as a cost or distance
- DA graph that is stored on disk
3.Easy
In an undirected graph, what is the degree of a vertex?
- AIts position in the adjacency list
- BThe number of edges connected to it
- CThe number of vertices in the graph
- DThe length of the longest path from it
4.Medium
AVL trees and red-black trees guarantee:
- AO(log n) height through rebalancing
- BThat keys are stored in insertion order
- CConstant-time search in every case
- DThat no node has two children
5.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 postorder traversal?
- A4 5 2 3 1
- B5 4 3 2 1
- C4 2 5 1 3
- D1 2 4 5 3
6.Medium
How long does a search for a word of length L take in a trie with a fixed alphabet?
- AO(L), independent of how many words are stored
- BO(L × n)
- CO(n), where n is the number of words
- DO(log n), where n is the number of words
7.Hard
Why do databases often use B+ trees rather than plain B-trees for indexes?
- AB+ trees use binary internal nodes, which reduces the number of disk reads
- BAll records are in linked leaves, which makes range scans efficient
- CB+ trees store data only in the root
- DB+ trees do not need to be balanced
8.Hard
You must keep the k smallest values from a stream of n numbers using O(k) memory. Which approach works in O(n log k) time?
- AA max-heap of size k, replacing its root when a smaller value arrives
- BA min-heap holding all n values, from which the k smallest are popped at the end
- CA sorted array of all n values
- DA FIFO queue of the last k values
Answer key
- 1. A · Stack
- 2. C · A graph in which each edge has a numeric value such as a cost or distance
- 3. B · The number of edges connected to it
- 4. A · O(log n) height through rebalancing
- 5. A · 4 5 2 3 1
- 6. A · O(L), independent of how many words are stored
- 7. B · All records are in linked leaves, which makes range scans efficient
- 8. A · A max-heap of size k, replacing its root when a smaller value arrives
Full step-by-step solutions: practise this topic on examproblems.com.