GATE CSE
First time here? Checkout the FAQ!
x
+2 votes
115 views

Consider M1 and M2 be two complete binary tree which satisfy max-heap property, each of size ‘n’. What is the time complexity to combine both M1 and M2 such that combine tree will be min heap tree?

  • O (n log n)
  • O (n)
  • O (n2)
  • O (n2 log n)
asked in DS by Active (2k points)  
retagged by | 115 views
M1 and M2 are contain total of 2n elements.(stores it in the array and construct min heap)

to construct min heap with n elements is o(nlogn)

=o(2nlog2n)=o(nlogn)

1 Answer

+2 votes
We have 2n number of elements and building a min heap using 2n elemets take O(2n) i.e.O(n) time
answered by (281 points)  
ypu call build heap which is O(n)
and then min heapify which is O(logn)
therefore O(nlogn) right?
@A_i_$_h

it will be O(n) only

in build heap procedure only, it will be converted to heap, then why call min heapify..
got it :)

Related questions

0 votes
0 answers
2
asked in DS by Vishal Goyal Active (2k points)   | 54 views
0 votes
0 answers
3
asked in DS by Vishal Goyal Active (2k points)   | 47 views


Top Users Sep 2017
  1. Habibkhan

    8796 Points

  2. rishu_darkshadow

    3572 Points

  3. Warrior

    2914 Points

  4. Arjun

    2840 Points

  5. A_i_$_h

    2550 Points

  6. manu00x

    2268 Points

  7. nikunj

    1990 Points

  8. Bikram

    1874 Points

  9. makhdoom ghaya

    1820 Points

  10. SiddharthMahapatra

    1718 Points


26,346 questions
33,927 answers
80,524 comments
31,231 users