GATE Exam  >  GATE Questions  >  Consider the array A = < 4, 1, 3, 2, 16, 9... Start Learning for Free
Consider the array A = < 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 >. After building a max heap from the array A, the height (the longest path from root to the leaf) of the heap and the sum of elements present in the root’s right subtree are equal to _______ and _______. (Root is at level 0)
  • a)
    3, 16
  • b)
    4, 19
  • c)
    3, 22
  • d)
    5, 25
Correct answer is option 'C'. Can you explain this answer?
Verified Answer
Consider the array A = < 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 >. Afte...
We can apply build max heap and the resultant max heap will have height equal to 3, and the elements present in the right subtree will be 10, 3, 9.
Therefore the sum will be equal to 10 + 3 + 9 = 22.
View all questions of this test
Most Upvoted Answer
Consider the array A = < 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 >. Afte...
Max Heap and Height Calculation
Max heap is a complete binary tree where the value of each node is greater than or equal to the values of its children. To calculate the height of a max heap, we need to consider the longest path from the root to the leaf.

Given Array A
A = < 4,="" 1,="" 3,="" 2,="" 16,="" 9,="" 10,="" 14,="" 8,="" 7="" />

Building Max Heap
1. Start with the last non-leaf node (n/2-1), which is 14 in this case.
2. Compare the parent node with its children and swap if necessary to maintain the max heap property.
3. Move to the previous non-leaf node and repeat the process until the root is reached.
4. After building the max heap, the array A will look like: < 16,="" 14,="" 10,="" 8,="" 7,="" 9,="" 3,="" 2,="" 4,="" 1="" />

Height Calculation
The height of a heap can be calculated as log2(n+1) - 1, where n is the number of elements in the heap.
In this case, the number of elements in the heap is 10. Therefore, the height of the heap is log2(10+1) - 1 = 3.

Sum of Elements in Right Subtree of Root
In a max heap, the root's right subtree will contain the second largest element in the heap. In this case, the second largest element is 14.
The sum of elements present in the root's right subtree is 14 + 8 + 7 = 29.
Therefore, the height of the heap is 3 and the sum of elements in the root's right subtree is 29, which corresponds to option C.
Explore Courses for GATE exam

Similar GATE Doubts

Consider the array A = < 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 >. After building a max heap from the array A, the height (the longest path from root to the leaf) of the heap and the sum of elements present in the root’s right subtree are equal to _______ and _______. (Root is at level 0)a)3, 16b)4, 19c)3, 22d)5, 25Correct answer is option 'C'. Can you explain this answer?
Question Description
Consider the array A = < 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 >. After building a max heap from the array A, the height (the longest path from root to the leaf) of the heap and the sum of elements present in the root’s right subtree are equal to _______ and _______. (Root is at level 0)a)3, 16b)4, 19c)3, 22d)5, 25Correct answer is option 'C'. Can you explain this answer? for GATE 2024 is part of GATE preparation. The Question and answers have been prepared according to the GATE exam syllabus. Information about Consider the array A = < 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 >. After building a max heap from the array A, the height (the longest path from root to the leaf) of the heap and the sum of elements present in the root’s right subtree are equal to _______ and _______. (Root is at level 0)a)3, 16b)4, 19c)3, 22d)5, 25Correct answer is option 'C'. Can you explain this answer? covers all topics & solutions for GATE 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the array A = < 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 >. After building a max heap from the array A, the height (the longest path from root to the leaf) of the heap and the sum of elements present in the root’s right subtree are equal to _______ and _______. (Root is at level 0)a)3, 16b)4, 19c)3, 22d)5, 25Correct answer is option 'C'. Can you explain this answer?.
Solutions for Consider the array A = < 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 >. After building a max heap from the array A, the height (the longest path from root to the leaf) of the heap and the sum of elements present in the root’s right subtree are equal to _______ and _______. (Root is at level 0)a)3, 16b)4, 19c)3, 22d)5, 25Correct answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for GATE. Download more important topics, notes, lectures and mock test series for GATE Exam by signing up for free.
Here you can find the meaning of Consider the array A = < 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 >. After building a max heap from the array A, the height (the longest path from root to the leaf) of the heap and the sum of elements present in the root’s right subtree are equal to _______ and _______. (Root is at level 0)a)3, 16b)4, 19c)3, 22d)5, 25Correct answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the array A = < 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 >. After building a max heap from the array A, the height (the longest path from root to the leaf) of the heap and the sum of elements present in the root’s right subtree are equal to _______ and _______. (Root is at level 0)a)3, 16b)4, 19c)3, 22d)5, 25Correct answer is option 'C'. Can you explain this answer?, a detailed solution for Consider the array A = < 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 >. After building a max heap from the array A, the height (the longest path from root to the leaf) of the heap and the sum of elements present in the root’s right subtree are equal to _______ and _______. (Root is at level 0)a)3, 16b)4, 19c)3, 22d)5, 25Correct answer is option 'C'. Can you explain this answer? has been provided alongside types of Consider the array A = < 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 >. After building a max heap from the array A, the height (the longest path from root to the leaf) of the heap and the sum of elements present in the root’s right subtree are equal to _______ and _______. (Root is at level 0)a)3, 16b)4, 19c)3, 22d)5, 25Correct answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the array A = < 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 >. After building a max heap from the array A, the height (the longest path from root to the leaf) of the heap and the sum of elements present in the root’s right subtree are equal to _______ and _______. (Root is at level 0)a)3, 16b)4, 19c)3, 22d)5, 25Correct answer is option 'C'. Can you explain this answer? tests, examples and also practice GATE tests.
Explore Courses for GATE exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev