What is the time complexity of Build Heap operation. Build Heap is used to build a max(or min) binary heap from a given array. Build Heap is used in Heap Sort as a first step for sorting.
Explanation: Following is algorithm for building a Heap of an input array A.
BUILD-HEAP(A) heapsize := size(A); for i := floor(heapsize/2) downto 1 do HEAPIFY(A, i); end for END
Although the worst case complexity looks like O(nLogn), upper bound of time complexity is O(n). See following links for the proof of time complexity.
- Data Structures | Heap | Question 9
- Data Structures | Heap | Question 2
- Data Structures | Balanced Binary Search Trees | Question 2
- Data Structures | Tree Traversals | Question 4
- Data Structures | Binary Trees | Question 1
- Johnson’s algorithm for All-pairs shortest paths | Implementation
- FIFO (First-In-First-Out) approach in Programming
- FIFO vs LIFO approach in Programming
- Sentence that contains all the given phrases
- Check if two trees have same structure
- Advantages of vector over array in C++
- Data Structures and Algorithms | Set 37
- Data Structures and Algorithms | Set 36
- Data Structures | Heap | Question 12
- Data Structures | Linked List | Question 17