Algorithms and Data Structures · Middle · Question 10 of 75
What are the costs of the main operations of a binary heap?
- 1Peek O(log n), insert O(1), extract min O(1)
- 2Peek O(1), insert O(n), extract min O(n)
- ✓Correct answer: Peek O(1), insert O(log n), extract min O(log n)
Explanation
The minimum sits at the root. Insert adds to the end and "sifts up"; extraction moves the last element to the root and "sifts down". Both walk one path of height log n.