First time here? Checkout the FAQ!
+2 votes

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)


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?

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
asked in DS by Vishal Goyal Active (2k points)   | 54 views
0 votes
0 answers
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
31,231 users