Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 52s1 days 16 hours 1 minutes 52 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 52s1 days 16 hours 1 minutes 52 seconds.

Sign in to watch this lesson
Algorithms - Linear Data Structures · 5:13
A binary heap is an array read as a tree: the children of index i sit at 2i+1 and 2i+2, and every parent is no larger than its children. We push 5, 3, 8, 1, 9, 2 with sift-up to get [1, 3, 2, 5, 9, 8], pop with sift-down to get [2, 3, 8, 5, 9], see why std::priority_queue is a max-heap by default, and measure bottom-up heapify against one push at a time on this Mac. Then two patterns: top-k with a size-k min-heap, and a first look at the running median with two heaps.