0
0
DSA C++programming~10 mins

Merge Sort Algorithm 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 find the middle index for splitting the array.

DSA C++
int mid = (left [1] right) / 2;
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction instead of addition.
Using multiplication which is incorrect here.
2fill in blank
medium

Complete the code to merge two sorted halves by comparing elements.

DSA C++
if (leftArr[i] [1] rightArr[j]) { merged[k++] = leftArr[i++]; } else { merged[k++] = rightArr[j++]; }
Drag options to blanks, or click blank then click option'
A<=
B<
C>=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of < causes wrong order.
Using <= or >= can cause duplicates or errors.
3fill in blank
hard

Fix the error in the recursive call to sort the right half.

DSA C++
mergeSort(arr, [1], right);
Drag options to blanks, or click blank then click option'
Amid
Bright - 1
Cmid + 1
Dleft
Attempts:
3 left
💡 Hint
Common Mistakes
Using mid instead of mid + 1 causes overlap.
Using right - 1 misses the last element.
4fill in blank
hard

Fill both blanks to copy remaining elements from left and right arrays after merging.

DSA C++
while (i < n1) merged[k++] = leftArr[1]; while (j < n2) merged[k++] = rightArr[2];
Drag options to blanks, or click blank then click option'
A[i++]
B[j++]
C[k++]
D[i]
Attempts:
3 left
💡 Hint
Common Mistakes
Using [k++] causes wrong indexing.
Not incrementing i or j causes infinite loops.
5fill in blank
hard

Fill all three blanks to copy merged array back to original array.

DSA C++
for (int idx = 0; idx < n1 + n2; idx++) arr[1] = merged[2]; [3]
Drag options to blanks, or click blank then click option'
A[left + idx]
B[idx]
C// end of copying
D[idx + left]
Attempts:
3 left
💡 Hint
Common Mistakes
Using arr[idx] overwrites wrong part of array.
Missing the comment line is okay but less clear.