Data Structures & AlgorithmsModerateGATE CS
In how many different ways can 'abcdabcd' be split into a sequence of words from the dictionary {a, ab, abc, bcd, cd, d, abcd} (every character used, order kept)?
- A. 15
- B. 17
- C. 16
- D. 32
Correct answer: C. 16
ways[i] = Σ ways[j] over dictionary words s[j..i−1], with ways[0] = 1; ways[8] = 16.
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
- Six sorted files have 14, 31, 34, 35, 36, 58 records. Merging two files of sizes a and b costs a + b. What is the minimum total cost to…
- An undirected connected graph has edges A–D, A–G, B–E, C–E, C–G, D–H, D–I, F–I, G–H. How many articulation points (cut vertices) and how…
- Bellman–Ford runs from A on the directed graph whose edges are relaxed in EVERY pass in this fixed order: C→D (1), A→F (8), F→C (3), D→A…
- Edit distance between PARAGRAPH and BINARY where insert and delete cost 1 each but a substitution costs 2: what is the minimum total cost?
- Bellman–Ford runs from A on the directed graph whose edges are relaxed in EVERY pass in this fixed order: D→B (4), F→D (8), D→C (2), A→E…
- A B-tree has minimum degree t = 4 (every non-root node has between 3 and 7 keys) and height 2 (a root-only tree has height 0). What are…