Data Structures & AlgorithmsVery hardProduct-company placement
Keys 55, 50, 19, 76, 39, 98, 34, 63, 58, 69 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. 39, 63, 50, 19, 76, 98, 34, 55 — longest chain 1
- B. ∅, ∅, 58→34→98→50, 19, 76, 69, ∅, 63→39→55 — longest chain 4
- C. ∅, ∅, 50→98→34→58, 19, 76, 69, ∅, 55→39→63 — longest chain 3
- D. ∅, ∅, 50→98→34→58, 19, 76, 69, ∅, 55→39→63 — longest chain 4
Correct answer: D. ∅, ∅, 50→98→34→58, 19, 76, 69, ∅, 55→39→63 — longest chain 4
Each key is appended to the chain at index k mod 8 in insertion order, giving buckets [∅, ∅, 50→98→34→58, 19, 76, 69, ∅, 55→39→63], whose longest chain has 4 key(s). This differs from open addressing (linear probing), which would spread keys like [39, 63, 50, 19, 76, 98, 34, 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
- A trie is built from the words {cat, card, den, cats, dog, do, cap}. Using the trie (walk the prefix's characters, then count all words in…
- Build a binary min-heap in place from the array [2, 63, 36, 74, 23, 20, 15, 22] using bottom-up heapify (sift-down from the last internal…
- Build a binary min-heap in place from the array [47, 72, 84, 82, 36, 61, 51, 7, 2] using bottom-up heapify (sift-down from the last…
- Undirected graph edges: E–C, C–A, B–E, B–C, A–B, A–E, C–D. Using a BFS 2-colouring, is this graph bipartite?
- A trie is built from the words {cat, card, dot, den, deed, dog}. Using the trie (walk the prefix's characters, then count all words in the…
- An undirected graph has adjacency lists (neighbours visited in alphabetical order) A: [B, C, G]; B: [A, E, G]; C: [A, G]; D: [F, G]; E…