0
0
DSA Typescriptprogramming~10 mins

Why Divide and Conquer and What It Gives You in DSA Typescript - Test Your Knowledge

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 Typescript
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 addition or subtraction instead of division.
Using multiplication which increases the length.
2fill in blank
medium

Complete the code to recursively sort the left half of the array.

DSA Typescript
const left = divideAndConquer(arr.slice(0, [1]));
Drag options to blanks, or click blank then click option'
Amid
Barr.length
C0
Darr.length - 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using the full length instead of mid.
Starting slice from mid instead of 0.
3fill in blank
hard

Fix the error in the merge function to combine two sorted arrays.

DSA Typescript
while (i < left.length && j [1] 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 which causes skipping the loop.
Using equality which stops early.
4fill in blank
hard

Fill in the blank to compare and merge elements correctly.

DSA Typescript
if (left[i] [1] right[j]) {
  result.push(left[i]);
  i++;
} else {
  result.push(right[j]);
  j++;
}
Drag options to blanks, or click blank then click option'
A!=
B>
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using equality which does not sort properly.
Using greater than in the wrong place.
5fill in blank
hard

Fill all three blanks to complete the divide and conquer merge sort function.

DSA Typescript
function mergeSort(arr: number[]): number[] {
  if (arr.length <= 1) return arr;
  const mid = Math.floor(arr.length [1] 2);
  const left = mergeSort(arr.slice(0, [2]));
  const right = mergeSort(arr.slice([3]));
  return merge(left, right);
}
Drag options to blanks, or click blank then click option'
A+
B/
Cmid
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of division for mid.
Incorrect slice indices causing wrong splits.