Data Structures & AlgorithmsHardGATE CS · Product-company placement
The words trie, tried, trip, try, tree are inserted into an empty trie (one node per character, shared prefixes share nodes, plus a root). How many nodes does the trie have (including the root), and how many nodes have two or more children?
- A. 21 nodes, 2 branching
- B. 9 nodes, 2 branching
- C. 10 nodes, 3 branching
- D. 10 nodes, 2 branching
Correct answer: D. 10 nodes, 2 branching
Nodes = distinct non-empty prefixes + root = 9 + 1 = 10, not the total letter count 20. A node branches when two different next letters follow its prefix; there are 2 such nodes.
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
- In the grid 21112 / 11110 / 10111 / 11111 (rows top to bottom; 2 = rotten, 1 = fresh, 0 = empty), every minute each rotten orange rots its…
- An undirected graph has edges A–E, A–H, B–F, C–E, C–G, D–G, D–H, E–F, E–G, F–H. BFS starts at A and always scans neighbours in…
- A tree on vertices 1–10 has edges 2–1, 3–2, 4–1, 5–4, 6–1, 7–3, 8–7, 9–5, 10–9. What is the size of a minimum DOMINATING set (every vertex…
- What is the length of the longest common subsequence of CONTEST and RECESSION, and how many DISTINCT longest common subsequences (as…
- A tree on vertices 1–8 has edges 2–1, 3–2, 4–1, 5–2, 6–5, 7–2, 8–1. What is the sum of the distances (in edges) over all unordered pairs…
- How many structurally different binary trees with 7 nodes have height EXACTLY 4 (height = edges on the longest root-to-leaf path)?