Bird
0
0
DSA Cprogramming~10 mins

Dutch National Flag Three Way Partition in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to swap two integers using a temporary variable.

DSA C
void swap(int *a, int *b) {
    int temp = *a;
    *a = [1];
    *b = temp;
}
Drag options to blanks, or click blank then click option'
A*b
B*a
Ca
Dtemp
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning 'a' instead of '*b'.
Using 'temp' instead of '*b'.
2fill in blank
medium

Complete the code to move the 'low' pointer forward when the current element is less than pivot.

DSA C
if (arr[i] < pivot) {
    swap(&arr[i], &arr[[1]]);
    low++;
    i++;
}
Drag options to blanks, or click blank then click option'
Apivot
Blow
Ci
Dhigh
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping with 'high' instead of 'low'.
Swapping with 'i' which is the current index.
3fill in blank
hard

Fix the error in the loop condition to correctly process all elements.

DSA C
while ([1] <= high) {
    if (arr[i] < pivot) {
        swap(&arr[i], &arr[low]);
        low++;
        i++;
    } else if (arr[i] > pivot) {
        swap(&arr[i], &arr[high]);
        high--;
    } else {
        i++;
    }
}
Drag options to blanks, or click blank then click option'
Ahigh
Blow
Cpivot
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'low' or 'high' as the loop variable incorrectly.
Comparing 'pivot' instead of an index.
4fill in blank
hard

Fill both blanks to initialize pointers correctly before the partition loop.

DSA C
int low = [1];
int high = [2];
Drag options to blanks, or click blank then click option'
A0
B1
Csize - 1
Dsize
Attempts:
3 left
💡 Hint
Common Mistakes
Setting 'low' to 1 instead of 0.
Setting 'high' to size instead of size - 1.
5fill in blank
hard

Fill all three blanks to complete the Dutch National Flag partition function.

DSA C
void dutch_national_flag(int arr[], int size, int pivot) {
    int low = [1];
    int high = [2];
    int i = [3];

    while (i <= high) {
        if (arr[i] < pivot) {
            swap(&arr[i], &arr[low]);
            low++;
            i++;
        } else if (arr[i] > pivot) {
            swap(&arr[i], &arr[high]);
            high--;
        } else {
            i++;
        }
    }
}
Drag options to blanks, or click blank then click option'
A0
Bsize - 1
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Starting 'i' or 'low' at 1 instead of 0.
Setting 'high' to size instead of size - 1.