Data Structures & AlgorithmsHardTCS NQT · Infosys pattern
Keys 92, 78, 40, 55, 53, 90, 42 are inserted via separate chaining (h(k) = k mod 5, new keys appended to the end of the chain) into a table of size 5 (buckets 0 to 4). What are the final bucket contents, and what is the longest chain length?
- A. 40, 55, 92, 78, 53 — longest chain 1
- B. 40→55→90, ∅, 92→42, 78→53, ∅ — longest chain 2
- C. 40→55→90, ∅, 92→42, 78→53, ∅ — longest chain 3
- D. 90→55→40, ∅, 42→92, 53→78, ∅ — longest chain 3
Correct answer: C. 40→55→90, ∅, 92→42, 78→53, ∅ — longest chain 3
Each key is appended to the chain at index k mod 5 in insertion order, giving buckets [40→55→90, ∅, 92→42, 78→53, ∅], whose longest chain has 3 key(s). This differs from open addressing (linear probing), which would spread keys like [40, 55, 92, 78, 53] 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 [53, 5, 2, 10, 30, 72, 65, 60] and inorder traversal [2, 5, 10, 30, 53, 60, 65, 72]. Reconstructing…
- A directed graph has edges E→C, B→E, A→E, C→A, B→C, A→D, E→D. Using 3-colour DFS (white/grey/black, a grey-to-grey back edge means a…
- A binary tree has preorder traversal [75, 38, 23, 7, 60, 94, 80, 95] and inorder traversal [7, 23, 38, 60, 75, 80, 94, 95]. Reconstructing…
- Undirected graph edges: D–A, D–B, A–C, B–C, A–B, D–C. Using a BFS 2-colouring, is this graph bipartite?
- 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)…
- Undirected graph edges: E–B, A–D, A–C, A–B, B–D. Using a BFS 2-colouring, is this graph bipartite?