Data Structures19 sections · 729 units
Open in Course

Heap Operations Overview

What heaps support

Three core operations:

1.1. Peek: return the root (min or max). Time: O(1)O(1).

2.2. Insert: add an element, maintain heap property. Time: O(logn)O(\log n).

3.3. Extract: remove and return the root, maintain heap property. Time: O(logn)O(\log n). The O(logn)O(\log n) comes from the tree height. A complete binary tree with nn nodes has height O(logn)O(\log n).