Module 5 · Heaps · Common Mistakes

Heaps: common mistakes

A heap is a handful of index formulas and two loops, and one wrong character breaks the order without any error. Each slip here runs a heap sort — add every number, then pollAll — so the output shows whether the heap still works: forgetting to bubble up, the left child at 2i, and comparing the right child with the parent.

Pick a mistake and press play: Wrong runs the code with the mistake until it breaks, and the code marks the wrong line in red. Fixed runs the corrected code on the same input, with the corrected line in green.

Mistake
Code