Data Structures & AlgorithmsHardGATE CS
The words graph, green, greed, grape, grass 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. 26 nodes, 4 branching
- B. 13 nodes, 4 branching
- C. 12 nodes, 4 branching
- D. 13 nodes, 5 branching
Correct answer: B. 13 nodes, 4 branching
Nodes = distinct non-empty prefixes + root = 12 + 1 = 13, not the total letter count 25. A node branches when two different next letters follow its prefix; there are 4 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 DAG with edges B→E, C→A, C→G, D→A, D→B, D→C, D→F, D→G, F→A, F→B, F→C, how many distinct directed paths are there from D to G, and…
- A DAG on vertices A–G has edges B→A, B→D, B→F, E→C, F→A, F→E, G→A, G→C. What order does Kahn's algorithm that always removes the…
- A 3-ary max-heap is stored in a 0-indexed array (children of i at 3i + 1 … 3i + 3): [51, 43, 34, 20, 27, 18, 3, 8, 17, 10]. After…
- What is the minimum number of edges m such that EVERY simple undirected graph with 9 vertices and m edges is guaranteed to be connected?
- In the grid 01210 / 11111 / 11121 / 01111 (rows top to bottom; 2 = rotten, 1 = fresh, 0 = empty), every minute each rotten orange rots its…
- A binary tree with distinct labels has INORDER E D I C A G H B F and LEVEL-ORDER I D H E G B C F A. What is its postorder traversal?