Challenge - 5 Problems
Merge Sort Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of merge sort on this array?
Given the array [38, 27, 43, 3, 9, 82, 10], what is the sorted array after applying merge sort?
DSA C
int arr[] = {38, 27, 43, 3, 9, 82, 10}; // After merge sort, what is the array?
Attempts:
2 left
💡 Hint
Think about how merge sort splits and merges the array in sorted order.
✗ Incorrect
Merge sort divides the array into halves recursively and merges them back in sorted order, resulting in a fully sorted array.
🧠 Conceptual
intermediate1:30remaining
Why does merge sort use divide and conquer?
Which of the following best explains why merge sort uses the divide and conquer approach?
Attempts:
2 left
💡 Hint
Divide and conquer means breaking a big problem into smaller ones.
✗ Incorrect
Merge sort divides the array into halves, sorts each half recursively, then merges the sorted halves to get the final sorted array.
❓ Predict Output
advanced2:00remaining
What is the output after merging two sorted halves?
Given two sorted halves: [3, 27, 38] and [9, 10, 43], what is the merged sorted array?
DSA C
int left[] = {3, 27, 38}; int right[] = {9, 10, 43}; // After merging left and right, what is the array?
Attempts:
2 left
💡 Hint
Merging means taking the smallest element from either half step by step.
✗ Incorrect
Merging two sorted arrays results in a single sorted array by comparing elements from both halves.
🔧 Debug
advanced2:30remaining
What error occurs in this merge sort code snippet?
Consider this snippet from a merge sort implementation in C:
void merge(int arr[], int l, int m, int r) {
int n1 = m - l + 1;
int n2 = r - m;
int L[n1], R[n2];
for (int i = 0; i < n1; i++)
L[i] = arr[l + i];
for (int j = 0; j < n2; j++)
R[j] = arr[m + 1 + j];
int i = 0, j = 0, k = l;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
arr[k] = L[i];
i++;
} else {
arr[k] = R[j];
j++;
}
k++;
}
while (i < n1) {
arr[k] = L[i];
i++;
k++;
}
while (j < n2) {
arr[k] = R[j];
j++;
k++;
}
}
What error will this code cause when compiled with standard C?
Attempts:
2 left
💡 Hint
Check if variable length arrays are supported in all C standards.
✗ Incorrect
Variable length arrays (L[n1], R[n2]) are not supported in C89 and some compilers without extensions, causing compilation errors.
🧠 Conceptual
expert2:00remaining
What is the time complexity of merge sort and why?
Which option correctly states the time complexity of merge sort and explains why?
Attempts:
2 left
💡 Hint
Think about how many times the array is split and how merging works.
✗ Incorrect
Merge sort divides the array into halves log n times and merges each level in linear time, resulting in O(n log n) complexity.