Data Structures & AlgorithmsVery hardIBM · Deloitte pattern
Keys 55, 72, 25, 37, 27, 49, 91 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. 27, 49, 72, 37, 25, 91, 55 — longest chain 1
- B. 49→91, ∅, 72→37, ∅, 25, ∅, 55→27 — longest chain 2
- C. 91→49, ∅, 37→72, ∅, 25, ∅, 27→55 — longest chain 2
- D. 49→91, ∅, 72→37, ∅, 25, ∅, 55→27 — longest chain 1
Correct answer: B. 49→91, ∅, 72→37, ∅, 25, ∅, 55→27 — longest chain 2
Each key is appended to the chain at index k mod 7 in insertion order, giving buckets [49→91, ∅, 72→37, ∅, 25, ∅, 55→27], whose longest chain has 2 key(s). This differs from open addressing (linear probing), which would spread keys like [27, 49, 72, 37, 25, 91, 55] 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 graph has edges (u–v: weight) A–B:4, B–D:7, A–D:15, A–C:29, B–C:28, C–D:29. What is the weight of its minimum spanning tree?
- Keys 27, 96, 68, 47, 51, 92, 12 are inserted in this order into an empty BST (no rebalancing). What is the height of the tree (edges on…
- An undirected graph has adjacency lists (neighbours visited in alphabetical order) A: [G]; B: [C]; C: [B, D]; D: [C, F, G]; E: [F]; F: [D…
- Keys 35, 45, 55 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- Keys 60, 70, 80 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- A binary tree has preorder traversal [90, 31, 36, 77, 58, 43, 83] and inorder traversal [31, 36, 43, 58, 77, 83, 90]. Reconstructing the…