Recall & Review
beginner Click to reveal answer
What is the main idea behind the Dutch National Flag problem?
It is to sort an array of three different values (like 0, 1, 2) in one pass using pointers, without extra space.
beginner Click to reveal answer
In the two-pointer Dutch Flag algorithm, what do the pointers 'low', 'mid', and 'high' represent?
'low' marks the boundary for 0s, 'mid' is the current element under consideration, and 'high' marks the boundary for 2s.
intermediate Click to reveal answer
Why does the Dutch Flag algorithm swap elements when mid points to 0 or 2?
Because 0s should be at the start and 2s at the end, swapping moves them to their correct partitions while mid moves forward for 0 and stays for 2.
beginner Click to reveal answer
What is the time complexity of the Dutch National Flag sorting algorithm?
It is O(n) because it makes only one pass through the array.
intermediate Click to reveal answer
Can the Dutch Flag algorithm be used to sort arrays with more than three distinct values?
No, it is specifically designed for three distinct values. For more values, other sorting methods are needed.
What does the 'mid' pointer do in the Dutch Flag algorithm?
✗ Incorrect
'mid' moves through the array checking each element to decide if it should be swapped.
When the element at 'mid' is 0, what action is taken?
✗ Incorrect
0s go to the start, so swap with 'low' and move both pointers forward.
What happens when the element at 'mid' is 2?
✗ Incorrect
2s go to the end, so swap with 'high' and move 'high' backward without moving 'mid' yet.
What is the space complexity of the Dutch Flag algorithm?
✗ Incorrect
It sorts the array in place using constant extra space.
Which of these is NOT a pointer used in the Dutch Flag algorithm?
✗ Incorrect
'start' is not used; the algorithm uses 'low', 'mid', and 'high'.
Explain how the two-pointer Dutch Flag algorithm sorts an array of 0s, 1s, and 2s in one pass.
Think about how you separate colors into three groups by moving pointers and swapping.
You got /4 concepts.
Describe the conditions under which the 'mid' pointer moves forward or stays in place during the Dutch Flag sorting.
Consider what happens after swapping with 'high' pointer.
You got /3 concepts.
