Recall & Review
beginner
What is the main idea behind the Dutch National Flag problem?
It is to sort an array containing three different values (like 0, 1, 2) in a single pass using pointers, without extra space.
Click to reveal answer
beginner
In the two-pointer Dutch Flag algorithm, what do the pointers low, mid, and high represent?
Low points to the boundary of 0s, mid is the current element under consideration, and high points to the boundary of 2s.
Click to reveal answer
intermediate
Why do we swap elements when nums[mid] is 0 or 2 in the Dutch Flag algorithm?
Because 0s should be moved to the front (low side) and 2s to the end (high side), swapping places them correctly while mid moves forward or stays to check the swapped element.
Click to reveal answer
beginner
What happens when nums[mid] is 1 in the Dutch Flag algorithm?
We simply move mid forward because 1s belong in the middle and are already in the correct place.
Click to reveal answer
beginner
What is the time complexity of the Dutch National Flag sorting algorithm?
It is O(n) because it makes a single pass through the array with constant time operations.
Click to reveal answer
In the Dutch Flag problem, which pointer moves forward when nums[mid] == 0?
✗ Incorrect
When nums[mid] is 0, we swap with nums[low], then move both low and mid forward.
What should you do when nums[mid] == 2 in the Dutch Flag algorithm?
✗ Incorrect
When nums[mid] is 2, swap with nums[high] and move high backward; mid stays to check the swapped element.
What is the initial position of the high pointer in the Dutch Flag algorithm?
✗ Incorrect
High pointer starts at the last index of the array.
How many passes does the Dutch Flag algorithm make over the array?
✗ Incorrect
The algorithm sorts the array in a single pass.
Which of these is NOT a benefit of the Dutch Flag algorithm?
✗ Incorrect
The algorithm does NOT use extra memory; it sorts in-place.
Explain how the two-pointer Dutch Flag algorithm sorts an array with values 0, 1, and 2.
Think about how you separate colors by moving pointers and swapping.
You got /4 concepts.
Describe the role of each pointer (low, mid, high) in the Dutch Flag sorting algorithm.
Imagine dividing the array into three parts as you sort.
You got /4 concepts.