GeeksforGeeks » Miscellaneous
A GATE 2007 CS question
(4 posts)-
Consider the process of inserting an element into a Max Heap, where the Max Heap is represented by an array. Suppose we perform a binary search on the path from the new leaf to the root to find the position for the newly inserted element, the number of comparisons performed is:
(A) Theta (log n )
(B) Theta (logLog n )
(C) Theta(n)
(D) Theta(nlog n) -
theta(log(log(n))
-
In binary search of an array of length n, the time complexity is O(logn).
Here, as we traverse from the leaf node to the root, if leaf node corresponds to an index j, where floor(n/2)+1 <=j<=n;
the total numbers in the path is of the order log(n).In fact, the answer is O(log(h)), where h is the height of the heap. height of tree is floor(logn)~ logn
So, answer is O(log(logn))
-
order of complexity in heap is directly proportional to the height of the tree there = O(log(h)) where h is the height..........[1]
we perform a binary search on the path from the new leaf to the root therefore it will consume O(logn) at each level...........[2]
from [1] and [2]
we can see that it can take the O(log(logn))
Reply
You must log in to post.