Data Structures & AlgorithmsHardProduct-company MCQ pattern
Keys 43, 46, 99, 82, 78, 23, 40, 44, 60, 34 are inserted via separate chaining (h(k) = k mod 5, new keys appended to the end of the chain) into a table of size 5 (buckets 0 to 4). What are the final bucket contents, and what is the longest chain length?
- A. 40→60, 46, 82, 43→78→23, 99→44→34 — longest chain 2
- B. 60→40, 46, 82, 23→78→43, 34→44→99 — longest chain 3
- C. 78, 46, 82, 43, 99 — longest chain 1
- D. 40→60, 46, 82, 43→78→23, 99→44→34 — longest chain 3
Correct answer: D. 40→60, 46, 82, 43→78→23, 99→44→34 — longest chain 3
Each key is appended to the chain at index k mod 5 in insertion order, giving buckets [40→60, 46, 82, 43→78→23, 99→44→34], whose longest chain has 3 key(s). This differs from open addressing (linear probing), which would spread keys like [78, 46, 82, 43, 99] 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
- A binary tree has preorder traversal [21, 13, 54, 28, 40, 34] and inorder traversal [13, 21, 28, 34, 40, 54]. Reconstructing the tree…
- What are the time complexities of P and Q? c int P(int n) { if (n <= 1) return 1; return P(n/2) + P(n/2); } int Q(int n) { if (n <= 1)…
- Keys 30, 11, 59, 70, 43, 35 are inserted via separate chaining (h(k) = k mod 8, new keys appended to the end of the chain) into a table of…
- Undirected graph edges: A–C, A–D, D–C, C–B. Using a BFS 2-colouring, is this graph bipartite?
- 0/1 knapsack, capacity 11. Items (weight, value): (4, 6), (1, 7), (6, 3), (2, 2). What is the maximum total value?
- Keys 92, 78, 40, 55, 53, 90, 42 are inserted via separate chaining (h(k) = k mod 5, new keys appended to the end of the chain) into a…