Data Structures & AlgorithmsVery hardTCS NQT · Infosys pattern
Keys 4, 74, 93, 84, 37, 87, 63 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. 84→63, ∅, 93→37, 87, 4→74, ∅, ∅ — longest chain 2
- B. 63→84, ∅, 37→93, 87, 74→4, ∅, ∅ — longest chain 2
- C. 84, 63, 93, 37, 4, 74, 87 — longest chain 1
- D. 84→63, ∅, 93→37, 87, 4→74, ∅, ∅ — longest chain 1
Correct answer: A. 84→63, ∅, 93→37, 87, 4→74, ∅, ∅ — longest chain 2
Each key is appended to the chain at index k mod 7 in insertion order, giving buckets [84→63, ∅, 93→37, 87, 4→74, ∅, ∅], whose longest chain has 2 key(s). This differs from open addressing (linear probing), which would spread keys like [84, 63, 93, 37, 4, 74, 87] 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
- Keys 79, 74, 70, 89, 2, 6, 8 are inserted via separate chaining (h(k) = k mod 7, new keys appended to the end of the chain) into a table…
- Keys 75, 53, 77, 17, 31, 29, 21, 5, 95 are inserted in this order into an empty BST (no rebalancing). What is the height of the tree…
- Directed edges: A→B (4), A→C (5), C→B (-4), B→D (1). Dijkstra's algorithm, which finalises each vertex once when it is removed from the…
- Keys 43, 46, 99, 82, 78, 23, 40, 44, 60, 34 are inserted via separate chaining (h(k) = k mod 5, new keys appended to the end of the chain)…
- A binary tree has preorder traversal [21, 13, 54, 28, 40, 34] and inorder traversal [13, 21, 28, 34, 40, 54]. Reconstructing the tree…
- What are the time complexities of P and Q? c int P(int n) { if (n <= 1) return 1; return P(n/2) + P(n/2); } int Q(int n) { if (n <= 1)…