Data Structures & AlgorithmsModerateGATE CS · Product-company placement
In how many different ways can 'catsanddogs' be split into a sequence of words from the dictionary {cat, cats, and, sand, dog, dogs, s} (every character used, order kept)?
- A. 5
- B. 7
- C. 6
- D. 12
Correct answer: C. 6
ways[i] = Σ ways[j] over dictionary words s[j..i−1], with ways[0] = 1; ways[11] = 6.
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
- The boolean expression T ^ T | T ^ F (T = true, F = false, & = AND, | = OR, ^ = XOR) can be fully parenthesised in 5 ways. In how many of…
- What is the edit distance (insert, delete, substitute; each cost 1) between MATRIX and STRATEGY?
- A B-tree has minimum degree t = 3 (every non-root node has between 2 and 5 keys) and height 3 (a root-only tree has height 0). What are…
- How many subsets of {1, 4, 8, 9, 10, 11, 12} have sum exactly 27?
- What is the maximum flow from S to T in the network with directed capacities A→B (15), A→C (9), A→T (12), B→T (12), C→B (12), S→A (6), S→B…
- An undirected graph has edges A–B, A–D, B–H, C–D, C–F, C–G, D–G, E–F, E–H, F–G. BFS starts at A and always scans neighbours in…