KickSolve • Free • Private

Heap Tree Visualizer

A complete binary tree that follows the heap property (Min-Heap or Max-Heap). Insert, extract the root, build a heap from a list, and watch every sift-up and sift-down explained step by step.

Min-Heap and Max-HeapArray form shown liveSift up and sift down explained

How to use the Heap Tree Visualizer on KickSolve

Three quick steps, no account needed.

Pick Min or MaxChoose Min-Heap (smallest on top) or Max-Heap (largest on top). Switching re-heapifies the current values.
Insert or buildInsert places a value in the next free slot, then swaps it upward. Type a comma list and press Build heap to see bottom-up heapify.
Extract the rootThe root leaves, the last node takes its place and sinks down. Repeat to get the values in sorted order (heap sort).

About the Heap Tree Visualizer on KickSolve

What it is and how it works.

What is a heap?

A heap is a complete binary tree that obeys the heap property. In a Min-Heap every parent is smaller than or equal to its children, so the minimum is at the root. In a Max-Heap every parent is larger than or equal to its children.

Key properties

  • Complete tree: every level full except possibly the last, filled left to right
  • Stored in an array: parent of i is (i-1)/2, children are 2i+1 and 2i+2
  • Peek at the root is O(1); insert and extract are O(log n)
  • Build heap from n values is O(n)
  • Not sorted: searching for an arbitrary value is O(n)

Real-world uses

  • Priority queues (task schedulers, Dijkstra, A*)
  • Heap sort
  • Finding the k largest or smallest items
  • Running median with two heaps

Comparing trees? Try the AVL Tree, Red-Black Tree, B-Tree or B+ Tree visualizer.

Heap Tree cases at a glance

The situations the step-by-step log will name for you.

OperationWhat happensTime
InsertAdd at the next free slot, then sift up while smaller than the parent (Min-Heap)O(log n)
Extract rootRemove the root, move the last node up, then sift down with the best childO(log n)
PeekRead the rootO(1)
Build heapHeapify from the last parent back to the rootO(n)
Delete valueFind it (O(n)), replace with the last node, sift up or downO(n)

Worked example

The same steps the visualizer animates for any input.

Min-Heap, insert 5, 3, 8, 1.
Insert 5: root.          [5]
Insert 3: below 5, 3 < 5, swap.   [3, 5]
Insert 8: parent 3, no swap.      [3, 5, 8]
Insert 1: index 3, parent 5, swap; parent 3, swap.   [1, 3, 8, 5]
Extract min: remove 1, move 5 to the root, swap with 3.   [3, 5, 8]

Heap Tree FAQ

Quick answers.

What is a heap?

A complete binary tree where every parent is ordered against its children: smaller (Min-Heap) or larger (Max-Heap).

What is the difference between Min-Heap and Max-Heap?

A Min-Heap keeps the smallest value at the root. A Max-Heap keeps the largest value at the root.

How is a heap stored in an array?

Level by level. For index i, the parent is (i-1)/2 and the children are 2i+1 and 2i+2.

How does heap insert work?

Add the value at the end, then swap it with its parent while it breaks the heap property (sift up).

How does extract work?

Remove the root, move the last node to the root, then swap it with its better child until the heap property holds (sift down).

Why is build-heap O(n) and not O(n log n)?

Most nodes are near the bottom and sift only a short way. The total work adds up to O(n).

Is a heap a binary search tree?

No. A heap only orders parent against children, not left against right, so it cannot be searched in O(log n).

Is the visualizer free and private?

Yes. Free, no signup, and everything runs in your browser.

More free tools from KickSolve

Other tree visualizers.