GATE 2006
191 questions
MCQ 1911-mark 191
Questions 101–105 of 191
An array X of n distinct integers is interpreted as a complete binary tree. The index of the first element of the array is 0. If only the root node does not satisfy the heap property, the algorithm to convert the complete binary tree into a heap has the best asymptotic time complexity of
Answer: (B)
We call the Heapify / Bubble down / Percolate down procedure on the root. In the worst case, it takes time So the correct option is .
The other options make no sense. With time we can build a whole heap, not just heapify the root. is larger than .
The other options make no sense. With time we can build a whole heap, not just heapify the root. is larger than .
An array X of n distinct integers is interpreted as a complete binary tree. The index of the first element of the array is 0. The index of the parent of element, is?
Answer: (D)
In an array tree with the first index 0, the node at index has its left child at and its right child at .
So for a node at index : if (odd) then ; if (even) then . Both cases give .
This equals : for odd , , and for even , ; subtracting 1 gives the values above.
Why the others fail: take , whose parent is index 0. (A) gives , wrong. (B) gives , wrong. (C) gives , wrong. (D) gives , correct.
Answer: (D)
So for a node at index : if (odd) then ; if (even) then . Both cases give .
This equals : for odd , , and for even , ; subtracting 1 gives the values above.
Why the others fail: take , whose parent is index 0. (A) gives , wrong. (B) gives , wrong. (C) gives , wrong. (D) gives , correct.
Answer: (D)
In a binary tree, the number of internal nodes of degree 1 is 5, and the number of internal nodes of degree 2 is 10. The number of leaf nodes in the binary tree is
Answer: (B)
Here the degree of a node is its number of children, so every node has degree 0, 1 or 2. Nodes of degree 0 are the leaves.
Every edge goes from a parent to a child, so the number of edges is the sum of the degrees: .
A tree has one more node than edges, so the total number of nodes is .
Leaves .
Answer: (B)
Every edge goes from a parent to a child, so the number of edges is the sum of the degrees: .
A tree has one more node than edges, so the total number of nodes is .
Leaves .
Answer: (B)
A scheme for storing binary trees in an array X is as follows. Indexing of X starts at 1 instead of 0. The root is stored at X[1]. For a node stored at X[i], the left child, if any, is stored in X[2i] and the right child, if any, in X[2i + 1]. To be able to store any binary tree on n vertices, the minimum size of X should be
Answer: (D)
The tree can be any binary tree on vertices, so X must be big enough for the worst case. The node at index has its children at and . Take :
The worst case is a chain in which every node is a right child. The root is at , and each step goes from index to , so the node at depth is at index . The last of nodes has depth , so it sits at .
No tree can need more. A node at depth has an index of at most , and with nodes the depth is at most . So the minimum size of X is .
Answer: (D)
| Best case | Worst case |
The worst case is a chain in which every node is a right child. The root is at , and each step goes from index to , so the node at depth is at index . The last of nodes has depth , so it sits at .
No tree can need more. A node at depth has an index of at most , and with nodes the depth is at most . So the minimum size of X is .
Answer: (D)
Suppose that we have numbers between 1 and 100 in a binary search tree and want to search for the number 55. Which of the following sequences CANNOT be the sequence of nodes examined?
Answer: (C)
Look at option C. The search goes through the nodes
At node the search key is larger, so the search moves to the right side of . After this, no later node can have a value smaller than .
So option C cannot be a search sequence. It is the wrong one.