Data Structures & AlgorithmsVery hardProduct-company placement
Keys 47, 33, 29, 18, 55, 67 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. ∅, 29, ∅, ∅, 18→67, 47→33, 55 — longest chain 1
- B. ∅, 29, ∅, ∅, 18→67, 47→33, 55 — longest chain 2
- C. ∅, 29, ∅, ∅, 67→18, 33→47, 55 — longest chain 2
- D. 55, 29, 67, ∅, 18, 47, 33 — longest chain 1
Correct answer: B. ∅, 29, ∅, ∅, 18→67, 47→33, 55 — longest chain 2
Each key is appended to the chain at index k mod 7 in insertion order, giving buckets [∅, 29, ∅, ∅, 18→67, 47→33, 55], whose longest chain has 2 key(s). This differs from open addressing (linear probing), which would spread keys like [55, 29, 67, ∅, 18, 47, 33] 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: A–B, C–B, A–D, D–B, C–D, C–A. Using a BFS 2-colouring, is this graph bipartite?
- A disjoint-set (union-find with union by rank and path compression) over 9 elements (0 to 8), each initially its own component, runs this…
- Directed edges: A→B (5), A→C (6), C→B (-3), B→D (1). Dijkstra's algorithm, which finalises each vertex once when it is removed from the…
- An undirected connected graph has edges A–B, B–C, C–D, D–E, E–F, F–G, G–H, D–F, F–H. How many articulation points (cut vertices) and how…
- Keys 14, 21, 49, 22, 15, 16, 33, 66 are inserted via separate chaining (h(k) = k mod 7, new keys appended to the end of the chain) into a…
- An undirected connected graph has edges A–B, B–C, C–D, D–E, E–F. How many articulation points (cut vertices) and how many bridges does it…