Data Structures & AlgorithmsHardIBM · Deloitte pattern
Keys 8, 91, 32, 54, 14, 31, 17, 21, 26 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. ∅, 26→21→31→91, 17→32, 8, 14→54 — longest chain 4
- B. ∅, 91→31→21→26, 32→17, 8, 54→14 — longest chain 4
- C. 14, 91, 32, 8, 54 — longest chain 1
- D. ∅, 91→31→21→26, 32→17, 8, 54→14 — longest chain 3
Correct answer: B. ∅, 91→31→21→26, 32→17, 8, 54→14 — longest chain 4
Each key is appended to the chain at index k mod 5 in insertion order, giving buckets [∅, 91→31→21→26, 32→17, 8, 54→14], whose longest chain has 4 key(s). This differs from open addressing (linear probing), which would spread keys like [14, 91, 32, 8, 54] 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
- Keys 56, 62, 60, 92, 46, 65, 74, 38, 72 are inserted in this order into an empty BST (no rebalancing). What is the height of the tree…
- A binary tree has preorder traversal [7, 75, 8, 32, 9, 18, 91, 86] and inorder traversal [7, 8, 9, 18, 32, 75, 86, 91]. Reconstructing the…
- Keys 43, 53, 63 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- A disjoint-set (union-find with union by rank and path compression) over 8 elements (0 to 7), each initially its own component, runs this…
- Undirected graph edges: D–C, B–C, A–C, A–B, A–D, B–D. Using a BFS 2-colouring, is this graph bipartite?
- Keys 64, 54, 44 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…