Heap Tree · Data Structures
32 questions · asked in 20 of 27 years (2000–2026)
MCQ 27 · MSQ 1 · NAT 41-mark 19 · 2-mark 13
2000Questions per year2026
Questions 6–10 of 32
Which one of the following sequences when stored in an array at locations A[1], . . . , A[10] forms a max-heap?
Answer: (B)
In a max-heap, each parent must be both of its children, which are and .
- Option 1: A[3] = 10 has a child A[6] = 14. This is False.
- Option 2: 23 17, 14; 17 7, 13; 14 10, 1; 7 5, 6; 13 12. This is True.
- Option 3: A[5] = 13 has a child A[10] = 15. This is False.
- Option 4: A[4] = 1 has children 12, 7. This is False.
Answer: 23, 17, 14, 7, 13, 10, 1, 5, 6, 12
- Option 1: A[3] = 10 has a child A[6] = 14. This is False.
- Option 2: 23 17, 14; 17 7, 13; 14 10, 1; 7 5, 6; 13 12. This is True.
- Option 3: A[5] = 13 has a child A[10] = 15. This is False.
- Option 4: A[4] = 1 has children 12, 7. This is False.
Answer: 23, 17, 14, 7, 13, 10, 1, 5, 6, 12
Let A be a priority queue for maintaining a set of elements. Suppose A is implemented using a max-heap data structure. The operation Extract-Max(A) extracts and deletes the maximum element from A. The operation Insert(A,key) inserts a new element key in A. The properties of a max-heap are preserved at the end of each of these operations.
When A contains n elements, which one of the following statements about the worst case running time of these two operations is TRUE?
When A contains n elements, which one of the following statements about the worst case running time of these two operations is TRUE?
Answer: (B)
A heap with n elements has a height of about log n.
- Extract-Max: take out the root, put the last element at the root, then heapify down along the height of the tree .
- Insert: put the new element at the end, then bubble it up toward the root .
Answer: Both run in O(log(n))
- Extract-Max: take out the root, put the last element at the root, then heapify down along the height of the tree .
- Insert: put the new element at the end, then bubble it up toward the root .
Answer: Both run in O(log(n))
Let H be a binary min-heap consisting of n elements implemented as an array. What is the worst case time complexity of an optimal algorithm to find the maximum element in H?
Answer: (C)
The largest value in a min-heap must be at one of the leaves. The leaves have no order among themselves, so we have to look at every one of them. This takes .
Answer:
Answer:
Consider the array representation of a binary min-heap containing 1023 elements. The minimum number of comparisons required to find the maximum in the heap is ___________.
Answer: 511
The largest value in a min-heap must sit at a leaf node. The heap has 1023 nodes, so the number of leaves is .
To get the maximum of these 512 elements, we need 512 1 = 511 comparisons.
Answer: 511
To get the maximum of these 512 elements, we need 512 1 = 511 comparisons.
Answer: 511
Consider the following statements:
I. The smallest element in a max-heap is always at a leaf node.
II. The second largest element in a max-heap is always a child of the root node.
III. A max-heap can be constructed from a binary search tree in time.
IV. A binary search tree can be constructed from a max-heap in time.
Which of the above statements is/are TRUE?
I. The smallest element in a max-heap is always at a leaf node.
II. The second largest element in a max-heap is always a child of the root node.
III. A max-heap can be constructed from a binary search tree in time.
IV. A binary search tree can be constructed from a max-heap in time.
Which of the above statements is/are TRUE?
Answer: (A)
Let us check each statement one by one:
- I: Any node that has a child is larger than that child. So the smallest element cannot have a child so it is a leaf TRUE.
- II: The 2nd largest element can only be smaller than the root. So its parent has to be the root TRUE.
- III: Build-heap works on any array (for example, the elements of the BST) and takes TRUE.
- IV: Building a BST from a heap in would give a comparison sort (by inorder traversal) FALSE.
Answer: I, II and III
- I: Any node that has a child is larger than that child. So the smallest element cannot have a child so it is a leaf TRUE.
- II: The 2nd largest element can only be smaller than the root. So its parent has to be the root TRUE.
- III: Build-heap works on any array (for example, the elements of the BST) and takes TRUE.
- IV: Building a BST from a heap in would give a comparison sort (by inorder traversal) FALSE.
Answer: I, II and III
Keep practising