Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to split the array into two halves.
DSA Javascript
const mid = Math.floor(arr.length [1] 2);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication instead of division.
Using addition or subtraction which does not find the middle.
✗ Incorrect
We divide the length of the array by 2 to find the middle index for splitting.
2fill in blank
mediumComplete the code to recursively call mergeSort on the left half.
DSA Javascript
const left = mergeSort(arr.slice(0, [1]));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the full array length instead of mid.
Using incorrect slice indices causing wrong subarrays.
✗ Incorrect
We slice the array from 0 to mid to get the left half for recursive sorting.
3fill in blank
hardFix the error in the merge function to correctly compare elements.
DSA Javascript
if (left[i] [1] right[j]) {
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using greater than which reverses sorting order.
Using equality or inequality which does not sort properly.
✗ Incorrect
We compare if left[i] is less than right[j] to merge in sorted order.
4fill in blank
hardFill both blanks to complete the while loop conditions for merging.
DSA Javascript
while (i [1] left.length && j [2] right.length) {
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using greater than or equal which causes index errors.
Using less than or equal which may cause out of bounds.
✗ Incorrect
We continue merging while i and j are less than their array lengths.
5fill in blank
hardFill all three blanks to complete the return statement merging arrays.
DSA Javascript
return [...merged, ...left.slice([1]), ...right.slice([2])]; let i = [3];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variables for slicing leftover elements.
Initializing i incorrectly causing merge errors.
✗ Incorrect
We slice left from i and right from j to add remaining elements; i starts at 0.