Dutch National Flag Algorithm

Array Layout Presets

Pointer Tracking

LOW
0
MID
0
HIGH
N-1

Algorithm Loop

1. Inspect arr[mid] Pending
2. Swap Elements Pending
3. Adjust Pointers Pending

The 3-Pointer Trick

LOW tracks the boundary for 0s.
HIGH tracks the boundary for 2s.
MID scans the array from left to right.

When mid > high, sorting is mathematically complete in $O(N)$ time.

Live Console Log

Waiting for actions...