Data Structures & AlgorithmsVery hardTCS NQT · Infosys pattern
Keys 56, 48, 53, 36, 81, 29, 64 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. 56, 64→29→36, ∅, ∅, 81→53, ∅, 48 — longest chain 3
- B. 56, 36→29→64, ∅, ∅, 53→81, ∅, 48 — longest chain 3
- C. 56, 36→29→64, ∅, ∅, 53→81, ∅, 48 — longest chain 2
- D. 56, 36, 29, 64, 53, 81, 48 — longest chain 1
Correct answer: B. 56, 36→29→64, ∅, ∅, 53→81, ∅, 48 — longest chain 3
Each key is appended to the chain at index k mod 7 in insertion order, giving buckets [56, 36→29→64, ∅, ∅, 53→81, ∅, 48], whose longest chain has 3 key(s). This differs from open addressing (linear probing), which would spread keys like [56, 36, 29, 64, 53, 81, 48] 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 binary tree has preorder traversal [72, 40, 18, 19, 54, 47, 92, 81] and inorder traversal [18, 19, 40, 47, 54, 72, 81, 92]…
- Build a binary min-heap in place from the array [37, 10, 58, 45, 19, 47, 86, 41] using bottom-up heapify (sift-down from the last internal…
- Build a binary min-heap in place from the array [34, 57, 50, 49, 69, 76, 15, 74] using bottom-up heapify (sift-down from the last internal…
- 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…
- An undirected graph has adjacency lists A:BCDG B:AEF C:A D:AE E:BD F:B G:A. Neighbours are always explored in alphabetical order. Which is…
- Edges A-E, D-E, B-E, A-C, A-B are added one by one to an initially empty graph on vertices {A, B, C, D, E}, using Union-Find (with path…