0
0
DSA Javascriptprogramming~10 mins

Merge Sort Algorithm in DSA Javascript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A+
B*
C/
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication instead of division.
Using addition or subtraction which does not find the middle.
2fill in blank
medium

Complete 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'
Aarr.length - 1
Bmid
C0
Darr.length
Attempts:
3 left
💡 Hint
Common Mistakes
Using the full array length instead of mid.
Using incorrect slice indices causing wrong subarrays.
3fill in blank
hard

Fix 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'
A<
B>
C===
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using greater than which reverses sorting order.
Using equality or inequality which does not sort properly.
4fill in blank
hard

Fill 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'
A<
B>
C<=
D>=
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.
5fill in blank
hard

Fill 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'
Ai
Bj
C0
Dmerged.length
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variables for slicing leftover elements.
Initializing i incorrectly causing merge errors.