GeeksforGeeks » Miscellaneous

A GATE 2007 CS question

(4 posts)
  • Started 1 year ago by sanjeev
  • Latest reply from Gurpreet Singh Thind
  1. sanjeev
    guest
    Posted 1 year ago #

    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)

  2. kuldeep
    guest
    Posted 1 year ago #

    theta(log(log(n))

  3. tapan.k.avasthi
    Member
    Posted 9 months ago #

    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))

  4. Gurpreet Singh Thind
    guest
    Posted 8 months ago #

    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.

RSS feed for this topic