Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to split the array into two halves.
DSA C#
int mid = arr.Length [1] 2;
Attempts:
3 left
💡 Hint
Common Mistakes
Using + or - instead of division to find the middle.
Using multiplication which increases the number.
✗ Incorrect
The middle index is found by dividing the length of the array by 2.
2fill in blank
mediumComplete the code to copy the left half of the array.
DSA C#
int[] left = new int[mid]; Array.[1](arr, 0, left, 0, mid);
Attempts:
3 left
💡 Hint
Common Mistakes
Using Clone which returns an object, not copying elements.
Using CopyTo which is an instance method, not static.
✗ Incorrect
Array.Copy copies elements from the source array to the destination array.
3fill in blank
hardFix the error in the merge function to compare elements correctly.
DSA C#
if (left[i] [1] right[j]) { arr[k++] = left[i++]; } else { arr[k++] = right[j++]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using > which would reverse the order.
Using == or != which do not order elements.
✗ Incorrect
We pick the smaller element first, so we use < to compare.
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 whole array twice.
Using mid which is an index, not an array.
✗ Incorrect
We recursively sort the left and right halves separately.
5fill in blank
hardFill all three blanks to complete the merge process indices.
DSA C#
int i = [1], j = [2], k = [3]; while (i < left.Length && j < right.Length) { if (left[i] < right[j]) { arr[k++] = left[i++]; } else { arr[k++] = right[j++]; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Starting indices at 1 which skips the first element.
Using different values for i, j, k causing index errors.
✗ Incorrect
Indices i, j, and k start at 0 to begin merging from the start of each array.
