In: Computer Science
buildHeap(A)
h = new empty heap
for each element e in A
h.insert(e)
What is the Big-O runtime of this version of buildHeap? Justify your answer.
Heap insertion is followed by heapify in order to maintain the heap property after insertion. Heapify function take order of height, O(h) time to update the heap.
Attached here is the derivation, as to how buildheap has O(n) time complexity. Please refer to stardard book or some website to know how the series expansion used in last step evaluates to 2.