GATE Exam  >  GATE Questions  >   Consider the following “Max-heapify” algorit... Start Learning for Free
Consider the following “Max-heapify” algorithm.Array has size at least n and 1in.After applying The Max-heapify noded at A[i], the result will be the subtree of A[1,….n] rooted at A[i] is a max-heapify.{ Assume that except root A[i], all its children satisfies heap property]
Max –heapify (int A[ ], int n,int i)
{ int p,m;
p = i;
while (2pn)
{
if(Y && Z)
m = 2p+1;
else m =2p;
if(A[p]< />
[swap (A[p],A[m]);
p=m;
}
else
return ;
}
}
Find missing statements at Y and Z respectively to apply the heapify for subtree rooted at A[i].
  • a)
    (2p + 1) n, A[2p + 1] > A[2p]
  • b)
    (2p + 1) n, A[2p + 1] < />
  • c)
    (2p + 1) n, A[2p + 1] < />
  • d)
    (2p + 1) n, A[2p + 1] < />
Correct answer is option 'B'. Can you explain this answer?
Verified Answer
Consider the following “Max-heapify” algorithm.Array has size at leas...
If A[2p+1]>A[2p] then m=2p+1
else m=2p Y is :(2p+1)≤n
Z is :A[2p+1]>A[2p]
So, option B is correct.
View all questions of this test
Most Upvoted Answer
Consider the following “Max-heapify” algorithm.Array has size at leas...
There seems to be a typo in the algorithm you provided. The line "if(Y < n="" &&="" a[y]="" /> A[p])" is incomplete. Could you please provide the complete condition and the missing lines of code?
Explore Courses for GATE exam
Consider the following “Max-heapify” algorithm.Array has size at least n and 1in.After applying The Max-heapify noded at A[i], the result will be the subtree of A[1,….n] rooted at A[i] is a max-heapify.{ Assume that except root A[i], all its children satisfies heap property]Max –heapify (int A[ ], int n,int i){ int p,m;p = i;while (2pn){if(Y && Z)m = 2p+1;else m =2p;if(A[p][swap (A[p],A[m]);p=m;}elsereturn ;}}Find missing statements at Y and Z respectively to apply the heapify for subtree rooted at A[i].a)(2p + 1) n, A[2p + 1] > A[2p]b)(2p + 1) n, A[2p + 1] c)(2p + 1) n, A[2p + 1] d)(2p + 1) n, A[2p + 1] Correct answer is option 'B'. Can you explain this answer?
Question Description
Consider the following “Max-heapify” algorithm.Array has size at least n and 1in.After applying The Max-heapify noded at A[i], the result will be the subtree of A[1,….n] rooted at A[i] is a max-heapify.{ Assume that except root A[i], all its children satisfies heap property]Max –heapify (int A[ ], int n,int i){ int p,m;p = i;while (2pn){if(Y && Z)m = 2p+1;else m =2p;if(A[p][swap (A[p],A[m]);p=m;}elsereturn ;}}Find missing statements at Y and Z respectively to apply the heapify for subtree rooted at A[i].a)(2p + 1) n, A[2p + 1] > A[2p]b)(2p + 1) n, A[2p + 1] c)(2p + 1) n, A[2p + 1] d)(2p + 1) n, A[2p + 1] Correct answer is option 'B'. 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 following “Max-heapify” algorithm.Array has size at least n and 1in.After applying The Max-heapify noded at A[i], the result will be the subtree of A[1,….n] rooted at A[i] is a max-heapify.{ Assume that except root A[i], all its children satisfies heap property]Max –heapify (int A[ ], int n,int i){ int p,m;p = i;while (2pn){if(Y && Z)m = 2p+1;else m =2p;if(A[p][swap (A[p],A[m]);p=m;}elsereturn ;}}Find missing statements at Y and Z respectively to apply the heapify for subtree rooted at A[i].a)(2p + 1) n, A[2p + 1] > A[2p]b)(2p + 1) n, A[2p + 1] c)(2p + 1) n, A[2p + 1] d)(2p + 1) n, A[2p + 1] Correct answer is option 'B'. 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 following “Max-heapify” algorithm.Array has size at least n and 1in.After applying The Max-heapify noded at A[i], the result will be the subtree of A[1,….n] rooted at A[i] is a max-heapify.{ Assume that except root A[i], all its children satisfies heap property]Max –heapify (int A[ ], int n,int i){ int p,m;p = i;while (2pn){if(Y && Z)m = 2p+1;else m =2p;if(A[p][swap (A[p],A[m]);p=m;}elsereturn ;}}Find missing statements at Y and Z respectively to apply the heapify for subtree rooted at A[i].a)(2p + 1) n, A[2p + 1] > A[2p]b)(2p + 1) n, A[2p + 1] c)(2p + 1) n, A[2p + 1] d)(2p + 1) n, A[2p + 1] Correct answer is option 'B'. Can you explain this answer?.
Solutions for Consider the following “Max-heapify” algorithm.Array has size at least n and 1in.After applying The Max-heapify noded at A[i], the result will be the subtree of A[1,….n] rooted at A[i] is a max-heapify.{ Assume that except root A[i], all its children satisfies heap property]Max –heapify (int A[ ], int n,int i){ int p,m;p = i;while (2pn){if(Y && Z)m = 2p+1;else m =2p;if(A[p][swap (A[p],A[m]);p=m;}elsereturn ;}}Find missing statements at Y and Z respectively to apply the heapify for subtree rooted at A[i].a)(2p + 1) n, A[2p + 1] > A[2p]b)(2p + 1) n, A[2p + 1] c)(2p + 1) n, A[2p + 1] d)(2p + 1) n, A[2p + 1] Correct answer is option 'B'. 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 following “Max-heapify” algorithm.Array has size at least n and 1in.After applying The Max-heapify noded at A[i], the result will be the subtree of A[1,….n] rooted at A[i] is a max-heapify.{ Assume that except root A[i], all its children satisfies heap property]Max –heapify (int A[ ], int n,int i){ int p,m;p = i;while (2pn){if(Y && Z)m = 2p+1;else m =2p;if(A[p][swap (A[p],A[m]);p=m;}elsereturn ;}}Find missing statements at Y and Z respectively to apply the heapify for subtree rooted at A[i].a)(2p + 1) n, A[2p + 1] > A[2p]b)(2p + 1) n, A[2p + 1] c)(2p + 1) n, A[2p + 1] d)(2p + 1) n, A[2p + 1] Correct answer is option 'B'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the following “Max-heapify” algorithm.Array has size at least n and 1in.After applying The Max-heapify noded at A[i], the result will be the subtree of A[1,….n] rooted at A[i] is a max-heapify.{ Assume that except root A[i], all its children satisfies heap property]Max –heapify (int A[ ], int n,int i){ int p,m;p = i;while (2pn){if(Y && Z)m = 2p+1;else m =2p;if(A[p][swap (A[p],A[m]);p=m;}elsereturn ;}}Find missing statements at Y and Z respectively to apply the heapify for subtree rooted at A[i].a)(2p + 1) n, A[2p + 1] > A[2p]b)(2p + 1) n, A[2p + 1] c)(2p + 1) n, A[2p + 1] d)(2p + 1) n, A[2p + 1] Correct answer is option 'B'. Can you explain this answer?, a detailed solution for Consider the following “Max-heapify” algorithm.Array has size at least n and 1in.After applying The Max-heapify noded at A[i], the result will be the subtree of A[1,….n] rooted at A[i] is a max-heapify.{ Assume that except root A[i], all its children satisfies heap property]Max –heapify (int A[ ], int n,int i){ int p,m;p = i;while (2pn){if(Y && Z)m = 2p+1;else m =2p;if(A[p][swap (A[p],A[m]);p=m;}elsereturn ;}}Find missing statements at Y and Z respectively to apply the heapify for subtree rooted at A[i].a)(2p + 1) n, A[2p + 1] > A[2p]b)(2p + 1) n, A[2p + 1] c)(2p + 1) n, A[2p + 1] d)(2p + 1) n, A[2p + 1] Correct answer is option 'B'. Can you explain this answer? has been provided alongside types of Consider the following “Max-heapify” algorithm.Array has size at least n and 1in.After applying The Max-heapify noded at A[i], the result will be the subtree of A[1,….n] rooted at A[i] is a max-heapify.{ Assume that except root A[i], all its children satisfies heap property]Max –heapify (int A[ ], int n,int i){ int p,m;p = i;while (2pn){if(Y && Z)m = 2p+1;else m =2p;if(A[p][swap (A[p],A[m]);p=m;}elsereturn ;}}Find missing statements at Y and Z respectively to apply the heapify for subtree rooted at A[i].a)(2p + 1) n, A[2p + 1] > A[2p]b)(2p + 1) n, A[2p + 1] c)(2p + 1) n, A[2p + 1] d)(2p + 1) n, A[2p + 1] Correct answer is option 'B'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the following “Max-heapify” algorithm.Array has size at least n and 1in.After applying The Max-heapify noded at A[i], the result will be the subtree of A[1,….n] rooted at A[i] is a max-heapify.{ Assume that except root A[i], all its children satisfies heap property]Max –heapify (int A[ ], int n,int i){ int p,m;p = i;while (2pn){if(Y && Z)m = 2p+1;else m =2p;if(A[p][swap (A[p],A[m]);p=m;}elsereturn ;}}Find missing statements at Y and Z respectively to apply the heapify for subtree rooted at A[i].a)(2p + 1) n, A[2p + 1] > A[2p]b)(2p + 1) n, A[2p + 1] c)(2p + 1) n, A[2p + 1] d)(2p + 1) n, A[2p + 1] Correct answer is option 'B'. 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