GATE Computer ScienceHardGATE CS (PYQ pattern)
Keys 50, 30, 70, 20, 40, 60, 80, 10, 25, 35, 45, 55, 65, 75, 85, 5, 12, 22, 27, 90 are inserted in this order into an empty BST (root at depth 0). What are its internal path length (sum of the depths of the 20 nodes) and its external path length (sum of the depths of the 21 NULL child links, a NULL link counted one level below its parent)?
- A. 54 and 94
- B. 54 and 74
- C. 54 and 75
- D. 74 and 94
Correct answer: A. 54 and 94
Depths: 50 at 0; 30, 70 at 1; 20, 40, 60, 80 at 2; 10, 25, 35, 45, 55, 65, 75, 85 at 3; 5, 12, 22, 27, 90 at 4. Internal path length = 0 + 2 + 8 + 24 + 20 = 54. For any binary tree with n nodes, E = I + 2n, so E = 54 + 40 = 94.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- How many structurally distinct binary trees (left and right children distinguished) with exactly 7 nodes have exactly 3 leaves?
- A full binary tree has every node with 0 or 2 children; left and right are distinguished. How many structurally different full binary…
- An undirected unweighted graph has edges 1-2, 1-3, 2-4, 2-5, 3-4, 3-6, 4-7, 5-7, 6-7, 6-8, 7-9, 8-9. Using BFS from vertex 1, what is the…
- A directed graph on vertices 1..4 has edges 1->2, 1->3, 2->3, 2->4, 3->1, 3->4, 4->1, 4->2. How many walks of length exactly 4 (edges…
- An undirected graph has 14 vertices, 20 edges and exactly 3 connected components. DFS is restarted from an unvisited vertex until all…
- A complete binary tree stored in an array has 1000 nodes. What is its height (a single node has height 0) and how many nodes are at the…