Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to split the array into two halves in Merge Sort.
DSA C#
int mid = arr.Length [1] 2;
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition or multiplication instead of division to find the middle.
Using subtraction which does not give the middle index.
✗ Incorrect
We divide the length by 2 to find the middle index for splitting the array.
2fill in blank
mediumComplete the code to copy the left half of the array in Merge Sort.
DSA C#
Array.Copy(arr, 0, left, 0, [1]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using the full array length instead of mid.
Using left.Length which might not be set correctly.
✗ Incorrect
We copy from index 0 to mid length to get the left half.
3fill in blank
hardFix the error in the merge function to correctly compare elements.
DSA C#
if (left[i] [1] right[j])
Attempts:
3 left
💡 Hint
Common Mistakes
Using greater than which reverses sorting order.
Using equality which does not help in sorting.
✗ Incorrect
We compare if left element is less than right to merge in sorted order.
4fill in blank
hardFill both blanks to complete the recursive calls for Merge Sort.
DSA C#
MergeSort([1]); MergeSort([2]);
Attempts:
3 left
💡 Hint
Common Mistakes
Calling MergeSort on the original array twice.
Using a temporary array instead of left or right.
✗ Incorrect
We recursively sort the left and right halves separately.
5fill in blank
hardFill all three blanks to complete the merge logic copying remaining elements.
DSA C#
while (i < [1]) arr[k++] = left[i++]; while (j < [2]) arr[k++] = right[j++]; return [3];
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong array lengths in loops causing index errors.
Returning a temporary array instead of the merged array.
✗ Incorrect
We copy remaining elements from left and right arrays and return the merged array.
