Data Structures & AlgorithmsHardGATE CS · Product-company placement
The words trial, tripod, trie, trip, tried, 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. 29 nodes, 2 branching
- B. 12 nodes, 2 branching
- C. 13 nodes, 3 branching
- D. 13 nodes, 2 branching
Correct answer: D. 13 nodes, 2 branching
Nodes = distinct non-empty prefixes + root = 12 + 1 = 13, not the total letter count 28. 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
- Keys 19, 93, 16, 51, 81, 18, 92, 41 inserted in this order build a BST. How many of the 8! orderings of these same 8 keys, inserted into…
- Keys 92, 49, 31, 85, 28, 73, 29, 81, 90 are inserted in that order into an empty AVL tree. What is the preorder traversal of the final tree?
- The words graph, green, greed, grape, grass are inserted into an empty trie (one node per character, shared prefixes share nodes, plus a…
- 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…