GATE 2007
184 questions
MCQ 1841-mark 184
Questions 81–85 of 184
The inorder and preorder traversal of a binary tree are d b e a f c g and a b d e c f g, respectively The postorder traversal of the binary tree is:
Answer: (A)
The first node in the preorder traversal is the root, so a is the root of the tree.
In the inorder traversal, every node on the left of is in the left subtree of . Every node on the right is in the right subtree of .
The second node in the preorder traversal is . It goes to the left subtree of , because it lies on the left of in the inorder list.
We continue in the same way and build the binary tree:
Postorder visits the left subtree, then the right subtree, then the root. Left subtree of : d e b. Right subtree of : f g c. Then the root a. So the postorder traversal is d e b f g c a.
Answer: (A)
In the inorder traversal, every node on the left of is in the left subtree of . Every node on the right is in the right subtree of .
The second node in the preorder traversal is . It goes to the left subtree of , because it lies on the left of in the inorder list.
We continue in the same way and build the binary tree:
Postorder visits the left subtree, then the right subtree, then the root. Left subtree of : d e b. Right subtree of : f g c. Then the root a. So the postorder traversal is d e b f g c a.
Answer: (A)
The maximum number of binary trees that can be formed with three unlabeled nodes is:
Answer: (B)
The number of binary trees with unlabeled nodes is the Catalan number .
For : .
Check by counting: with the root taken out, the other 2 nodes go as (0 left, 2 right), (1 left, 1 right) or (2 left, 0 right). These give 2, 1 and 2 trees, so 2 + 1 + 2 = 5.
Note also that the number of binary search trees on distinct keys is the same Catalan number, equal to the number of unlabeled binary trees.
Answer: (B)
For : .
Check by counting: with the root taken out, the other 2 nodes go as (0 left, 2 right), (1 left, 1 right) or (2 left, 0 right). These give 2, 1 and 2 trees, so 2 + 1 + 2 = 5.
Note also that the number of binary search trees on distinct keys is the same Catalan number, equal to the number of unlabeled binary trees.
Answer: (B)
The height of a binary tree is the maximum number of edges in any root to leaf path. The maximum number of nodes in a binary tree of height h is:
Answer: (C)
Height is counted in edges, so a tree of height has levels 0 to . Level holds at most nodes. So the most nodes are
Test it on small trees. For there is just the root, 1 node, and . For the root has two children, 3 nodes, and . The other options fail at : (A) gives 0, (B) gives and (D) gives 2.
Answer: (C)
Test it on small trees. For there is just the root, 1 node, and . For the root has two children, 3 nodes, and . The other options fail at : (A) gives 0, (B) gives and (D) gives 2.
Answer: (C)
A complete n-ary tree is a tree in which each node has n children or no children. Let I be the number of internal nodes and L be the number of leaves in a complete n-ary tree. If L = 41, and I = 10, what is the value of n?
Answer: (C)
Every node except the root is a child of exactly one internal node, and each internal node has children. So the total number of nodes is .
The total is also . So , which gives .
Put in and :
Answer: (C)
The total is also . So , which gives .
Put in and :
Answer: (C)
When searching for the key value 60 in a binary search tree, nodes containing the key values 10, 20, 40, 50, 70, 80, 90 are traversed, not necessarily in the order given. How many different orders are possible in which these key values can occur on the search path from the root to the node containing the value 60?
Answer: (A)
In a BST search, suppose we move from to while looking for . Then we will never meet later. So if and are visited, they are visited in that fixed order. In the same way, and are visited in a fixed order. So the answer we need is
(This is because only one order is valid for the smaller numbers and only one order is valid for the larger numbers.)
Correct Answer: