Print the biggest K elements in a given heap in O(K*log(K))?

前端 未结 5 2021
粉色の甜心
粉色の甜心 2020-12-03 01:56

Given the following problem , I\'m not completely sure with my current solution :

Question :

Given a maximum heap with n ele

5条回答
  •  情书的邮戳
    2020-12-03 02:40

    Indeed, it is too easy, extracting the max element is O(log(N)) where N is the size of the heap. and N≠K.

    I will add that searching for a random element is O(N) and not O(Log(N)), but in this case we want to extract the max.

提交回复
热议问题