Data Structures & AlgorithmsVery hardTCS NQT · Infosys pattern
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 of size 7 (buckets 0 to 6). What are the final bucket contents, and what is the longest chain length?
- A. 70, 8, 2→79, ∅, 74, 89, 6 — longest chain 2
- B. 70, 8, 79→2, ∅, 74, 89, 6 — longest chain 1
- C. 70, 8, 79→2, ∅, 74, 89, 6 — longest chain 2
- D. 70, 8, 79, 2, 74, 89, 6 — longest chain 1
Correct answer: C. 70, 8, 79→2, ∅, 74, 89, 6 — longest chain 2
Each key is appended to the chain at index k mod 7 in insertion order, giving buckets [70, 8, 79→2, ∅, 74, 89, 6], whose longest chain has 2 key(s). This differs from open addressing (linear probing), which would spread keys like [70, 8, 79, 2, 74, 89, 6] 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 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)…
- Keys 30, 11, 59, 70, 43, 35 are inserted via separate chaining (h(k) = k mod 8, new keys appended to the end of the chain) into a table of…