GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Among all binary trees (left and right children distinguished) with 6 nodes whose preorder traversal is 1 2 3 4 5 6, how many have an inorder traversal that begins with 3?
- A. 42
- B. 28
- C. 14
- D. 5
Correct answer: B. 28
The inorder starts at the leftmost node, so the path from the root goes left, left: 2 is the left child of 1, 3 is the left child of 2, and 3 has no left child. The remaining nodes 4, 5, 6 (in preorder) fill three places in order: the right subtree of 3, then the right subtree of 2, then the right subtree of 1. The number of ways to split 3 preorder-consecutive nodes into three possibly empty binary trees is the coefficient of x^3 in C(x)^3 = 28 (brute force over all 132 trees agrees).
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A complete binary tree (every level full except possibly the last, which is filled from the left) has exactly 300 leaves. Which node…
- A rooted tree has 6 nodes with 2 children, 5 nodes with 3 children and 4 nodes with 4 children; every other node is a leaf. How many nodes…
- How many structurally different binary search trees can be built on the keys 1..7 such that the height is at most 3 (a single node has…
- Among all 429 structurally different binary search trees on the keys 1 to 7, in how many is key 3 a leaf?
- Keys 50, 30, 80, 20, 40, 70, 90, 10, 25, 35, 45, 5, 12, 22, 27 are inserted in this order into an empty BST. An iterative preorder…
- Keys 50, 30, 80, 20, 40, 70, 90, 10, 25, 35, 45, 5, 12, 22, 27 are inserted in this order into an empty BST. Its level-order traversal…