Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Dictionary D = {bcm, bct, blr, erl, etm, ncm, nrl, ocl, prm, sco, sct, snl} (all words have 3 letters). Starting from the word 'ocm', a move changes exactly one letter, and every word you move to must be in D. What is the minimum number of words in a valid sequence from 'ocm' to 'sco' (counting both endpoints; 'ocm' itself need not be in D)?
- A. 7
- B. 4
- C. 3
- D. 5
Correct answer: D. 5
BFS over one-letter moves inside D gives 4 moves, so 5 words including both endpoints. Forgetting to count the start word gives one less, and Hamming distance ignores the dictionary.
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
- Tree with vertices 0 to 9, root 0, edges 0–1, 1–2, 0–3, 2–4, 3–5, 0–6, 4–7, 3–8, 6–9 (parent–child). Vertex weights (vertex:weight) 0:19…
- Array A = [2, 4, 4, 1, 3, 5, 3, 5, 4]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly…
- A binary tree with distinct letters has preorder FDEABC and inorder ABEDCF. What is its postorder traversal (left, right, root), written…
- Points A(9,0), B(1,7), C(9,9), D(2,1), E(5,5), F(4,3) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| +…
- Directed weighted graph on vertices A, B, C, D with edges A→C (-2); B→A (3); D→C (0); B→D (5); A→D (2); D→B (-4); C→B (-3). Source A. Run…
- Array A = [3, 4, 4, 1, 4, 3, 1]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly…