What information entered the process?
Labs / Computer Science
Binary Heap Builder
A heap is a tree that lives inside a plain array. Insert a value and watch it bubble up until the ordering rule holds again; extract the root and watch the last element sink back down. Every comparison and swap is highlighted at the same time in the tree and in the array beneath it.
Labs / Computer Science / Binary Heap Builder
Binary Heap Builder
A heap is a tree that lives inside a plain array. Insert a value and watch it bubble up until the ordering rule holds again; extract the root and watch the last element sink back down. Every comparison and swap is highlighted at the same time in the tree and in the array beneath it.
Why it matters
Why explore this?
Computer science turns clear rules into reliable processes. This model lets you step through those rules and see how each decision changes the result.
Explore
Try the model
Investigate
Questions to test
Predict first, try it in the model, then use what you observe to answer.
What to try
- Insert a value smaller than everything else into a min-heap. How many swaps does it take to reach the root, and does that match the tree's height?
- Turn off auto-play and press Step. At each stop, which two array indices are being compared — and how do they relate as parent and child?
- Flip from min-heap to max-heap. Which value jumps to the root, and why does the whole array rearrange the instant you switch?
- Extract the root a few times in a row. Why does the last element get moved to the top first, instead of simply pulling up the smaller child?
- For an array index i, is its parent always at ⌊(i−1)/2⌋ and its children at 2i+1 and 2i+2? Watch the readouts and check.
Explain
Make sense of what happened
Trace the process one step at a time. Name the rule used at each important step, then explain why the final result follows from those rules.
Check
Before you leave
Which rule changed it?
Why did the process produce this result?
If you can answer all three using evidence from the model, you understand the main idea. If not, return to Explore and change one setting at a time.