Data Structures & AlgorithmsHardProduct-company placement
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 size 8 (buckets 0 to 7). What are the final bucket contents, and what is the longest chain length?
- A. ∅, ∅, ∅, 35→43→59→11, ∅, ∅, 70→30, ∅ — longest chain 4
- B. 35, ∅, ∅, 11, 59, 43, 30, 70 — longest chain 1
- C. ∅, ∅, ∅, 11→59→43→35, ∅, ∅, 30→70, ∅ — longest chain 4
- D. ∅, ∅, ∅, 11→59→43→35, ∅, ∅, 30→70, ∅ — longest chain 3
Correct answer: C. ∅, ∅, ∅, 11→59→43→35, ∅, ∅, 30→70, ∅ — longest chain 4
Each key is appended to the chain at index k mod 8 in insertion order, giving buckets [∅, ∅, ∅, 11→59→43→35, ∅, ∅, 30→70, ∅], whose longest chain has 4 key(s). This differs from open addressing (linear probing), which would spread keys like [35, ∅, ∅, 11, 59, 43, 30, 70] 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
- 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…
- A binary tree has preorder traversal [53, 5, 2, 10, 30, 72, 65, 60] and inorder traversal [2, 5, 10, 30, 53, 60, 65, 72]. Reconstructing…
- A directed graph has edges E→C, B→E, A→E, C→A, B→C, A→D, E→D. Using 3-colour DFS (white/grey/black, a grey-to-grey back edge means a…
- A binary tree has preorder traversal [75, 38, 23, 7, 60, 94, 80, 95] and inorder traversal [7, 23, 38, 60, 75, 80, 94, 95]. Reconstructing…