How can building a heap be O(n) time complexity?

后端 未结 17 2422
礼貌的吻别
礼貌的吻别 2020-11-22 05:33

Can someone help explain how can building a heap be O(n) complexity?

Inserting an item into a heap is O(log n), and the insert is repeated n/2 times (t

17条回答
  •  情话喂你
    2020-11-22 05:49

    Proof of O(n)

    The proof isn't fancy, and quite straightforward, I only proved the case for a full binary tree, the result can be generalized for a complete binary tree.

提交回复
热议问题