Data Structures & AlgorithmsVery hardAmazon/Microsoft SDE pattern
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) into a table of size 7 (buckets 0 to 6). What are the final bucket contents, and what is the longest chain length?
- A. 18, 97, 3, 38, 87, 73, 13 — longest chain 1
- B. 98, ∅, 72, 38→87→73→3, 18, 68, 13→97 — longest chain 4
- C. 98, ∅, 72, 38→87→73→3, 18, 68, 13→97 — longest chain 3
- D. 98, ∅, 72, 3→73→87→38, 18, 68, 97→13 — longest chain 4
Correct answer: B. 98, ∅, 72, 38→87→73→3, 18, 68, 13→97 — longest chain 4
Each key is appended to the chain at index k mod 7 in insertion order, giving buckets [98, ∅, 72, 38→87→73→3, 18, 68, 13→97], whose longest chain has 4 key(s). This differs from open addressing (linear probing), which would spread keys like [18, 97, 3, 38, 87, 73, 13] 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 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…
- Keys 41, 31, 21 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- Keys 38, 48, 58 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- Undirected graph edges: B–D, C–A, E–B, E–A, D–E, C–B, A–B. Using a BFS 2-colouring, is this graph bipartite?
- A directed graph has edges E→A, C→D, D→B, C→E, D→C. Using 3-colour DFS (white/grey/black, a grey-to-grey back edge means a cycle), does…