0
0
DSA Javascriptprogramming~10 mins

Quick Sort Partition Lomuto and Hoare 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 select the pivot as the last element in Lomuto partition.

DSA Javascript
function lomutoPartition(arr, low, high) {
  let pivot = arr[1];
  let i = low - 1;
  for (let j = low; j < high; j++) {
    if (arr[j] <= pivot) {
      i++;
      [arr[i], arr[j]] = [arr[j], arr[i]];
    }
  }
  [arr[i + 1], arr[high]] = [arr[high], arr[i + 1]];
  return i + 1;
}
Drag options to blanks, or click blank then click option'
A[low]
B[high]
C[low + 1]
D[0]
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing the first element as pivot instead of the last.
Using an index outside the current subarray.
2fill in blank
medium

Complete the code to swap elements in Lomuto partition when arr[j] is less than or equal to pivot.

DSA Javascript
if (arr[j] [1] pivot) {
  i++;
  [arr[i], arr[j]] = [arr[j], arr[i]];
}
Drag options to blanks, or click blank then click option'
A<=
B>
C<
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using only '<' and missing equal elements.
Using '>' which reverses the logic.
3fill in blank
hard

Fix the error in the Hoare partition loop condition to correctly partition the array.

DSA Javascript
while (arr[i] [1] pivot) i++;
while (arr[j] [2] pivot) j--;
Drag options to blanks, or click blank then click option'
A<
B<=
C>=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= or >= which can cause infinite loops.
Swapping the comparison directions.
4fill in blank
hard

Fill both blanks to complete the Hoare partition swap condition and return statement.

DSA Javascript
if (i >= j) return [1];
[arr[i], arr[j]] = [arr[j], arr[i]];

// Return index to split array
return [2];
Drag options to blanks, or click blank then click option'
Aj
Bi
Clow
Dhigh
Attempts:
3 left
💡 Hint
Common Mistakes
Returning i instead of j.
Returning low or high which are boundaries, not partition index.
5fill in blank
hard

Fill all three blanks to complete the Lomuto partition function with correct pivot selection, swap, and return.

DSA Javascript
function lomutoPartition(arr, low, high) {
  let pivot = arr[1];
  let i = low - 1;
  for (let j = low; j < high; j++) {
    if (arr[j] [2] pivot) {
      i++;
      [arr[i], arr[j]] = [arr[j], arr[i]];
    }
  }
  [arr[i + 1], arr[high]] = [arr[high], arr[i + 1]];
  return [3];
}
Drag options to blanks, or click blank then click option'
A[high]
B<=
Ci + 1
D[low]
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong pivot index.
Using wrong comparison operator.
Returning wrong partition index.