Data Structures & AlgorithmsHardProduct-company MCQ pattern
Keys 14, 21, 49, 22, 15, 16, 33, 66 are inserted via separate chaining (h(k) = k mod 7, new keys appended to the end of the chain) into a table of size 7 (buckets 0 to 6). What are the final bucket contents, and what is the longest chain length?
- A. 49→21→14, 15→22, 16, 66, ∅, 33, ∅ — longest chain 3
- B. 14→21→49, 22→15, 16, 66, ∅, 33, ∅ — longest chain 2
- C. 14, 21, 49, 22, 15, 16, 33 — longest chain 1
- D. 14→21→49, 22→15, 16, 66, ∅, 33, ∅ — longest chain 3
Correct answer: D. 14→21→49, 22→15, 16, 66, ∅, 33, ∅ — longest chain 3
Each key is appended to the chain at index k mod 7 in insertion order, giving buckets [14→21→49, 22→15, 16, 66, ∅, 33, ∅], whose longest chain has 3 key(s). This differs from open addressing (linear probing), which would spread keys like [14, 21, 49, 22, 15, 16, 33] into single-slot buckets instead of chains.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- An undirected connected graph has edges A–B, B–C, C–D, D–E, E–F. How many articulation points (cut vertices) and how many bridges does it…
- Keys 50, 60, 70 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- Directed edges: A→B (6), A→C (6), C→B (-5), B→D (1). Dijkstra's algorithm, which finalises each vertex once when it is removed from the…
- Keys 38, 13, 87, 73, 18, 97, 3, 68, 72, 98 are inserted via separate chaining (h(k) = k mod 7, new keys appended to the end of the chain)…
- A trie is built from the words {den, deed, do, cat, cap, dot}. Using the trie (walk the prefix's characters, then count all words in the…
- A binary tree has preorder traversal [11, 83, 45, 67, 61, 47, 95] and inorder traversal [11, 45, 47, 61, 67, 83, 95]. Reconstructing the…