Skip to main content

Dutch National Flag

Learn Dutch National Flag (Arrays, Data Structures & Algorithms) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

The Dutch National Flag Problem Named by Edsger Dijkstra after the three horizontal stripes of the Dutch flag: given an array of only three distinct values (classically 0, 1, 2), sort it in a single pass with O(1) extra space - no counting sort, no comparison sort needed. Three pointers partition the array into three zones as they scan: low - boundary of the "all 0s" zone (everything before it is 0) mid - the current element being examined high - boundary of the "all 2s" zone (everything after it is 2)

More lessons in Arrays