Data Structures & AlgorithmsVery hardGATE CS · ICPC regional · Product Company SDE
Keys 18, 24, 4, 33, 84, 49, 74, 69, 8, 79 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. 24→8, 33→49, 18→74, ∅, 4→84, 69, ∅, 79 — longest chain 1
- B. 8→24, 49→33, 74→18, ∅, 84→4, 69, ∅, 79 — longest chain 2
- C. 24, 33, 18, 49, 4, 84, 74, 69 — longest chain 1
- D. 24→8, 33→49, 18→74, ∅, 4→84, 69, ∅, 79 — longest chain 2
Correct answer: D. 24→8, 33→49, 18→74, ∅, 4→84, 69, ∅, 79 — longest chain 2
Each key is appended to the chain at index k mod 8 in insertion order, giving buckets [24→8, 33→49, 18→74, ∅, 4→84, 69, ∅, 79], whose longest chain has 2 key(s). This differs from open addressing (linear probing), which would spread keys like [24, 33, 18, 49, 4, 84, 74, 69] 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: E–B, A–D, A–C, A–B, B–D. Using a BFS 2-colouring, is this graph bipartite?
- A directed graph has edges C→A, B→D, D→B, D→C, D→A. Using 3-colour DFS (white/grey/black, a grey-to-grey back edge means a cycle), does…
- A directed graph has edges A→B, C→D, D→C, C→B. Using 3-colour DFS (white/grey/black, a grey-to-grey back edge means a cycle), does this…
- Build a binary min-heap in place from the array [73, 61, 88, 9, 29, 24, 58, 42] using bottom-up heapify (sift-down from the last internal…
- A directed graph has edges D→B, C→D, A→B, D→C. Using 3-colour DFS (white/grey/black, a grey-to-grey back edge means a cycle), does this…
- A disjoint-set (union-find with union by rank and path compression) over 7 elements (0 to 6), each initially its own component, runs this…