GATE Computer ScienceVery hardGATE CS (PYQ pattern)
How many distinct binary trees (left and right children are distinguished) on nodes 1..5 have preorder 1 2 3 4 5 and postorder 5 4 3 2 1?
- A. 16
- B. 1
- C. 14
- D. 5
Correct answer: A. 16
Preorder 12345 with postorder 54321 forces each node to have exactly one child (a chain). Each of the 4 non-root nodes is a left or a right child independently: 2^4 = 16 trees. Preorder + postorder cannot tell left from right for a lone child.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- 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…
- 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…