Asymptotic time complexity of inserting n elements to a binary heap already containing n elements

前端 未结 3 664
予麋鹿
予麋鹿 2021-01-05 06:58

Suppose we have a binary heap of n elements and wish to insert n more elements(not necessarily one after other). What would be the total time required for this?

I th

3条回答
  •  天命终不由人
    2021-01-05 07:53

    given : heap of n elements and n more elements to be inserted. So in the end there will be 2*n elements. since heap can be created in 2 ways 1. Successive insertion and 2. Build heap method. Amoung these build heap method takes O(n) time to construct heap which is explained in How can building a heap be O(n) time complexity?. so total time required is O(2*n) which is same as O(n)

提交回复
热议问题