0
0
DSA Javascriptprogramming~20 mins

Quick Sort Partition Lomuto and Hoare in DSA Javascript - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Quick Sort Partition Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Lomuto Partition on Array
What is the output array after applying Lomuto partition on the array [8, 3, 7, 6, 2] with pivot as last element?
DSA Javascript
function lomutoPartition(arr, low, high) {
  let pivot = arr[high];
  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 arr;
}

const arr = [8, 3, 7, 6, 2];
lomutoPartition(arr, 0, arr.length - 1);
console.log(arr);
A[2, 3, 7, 6, 8]
B[3, 2, 7, 6, 8]
C[2, 3, 6, 7, 8]
D[8, 3, 7, 6, 2]
Attempts:
2 left
💡 Hint
Remember Lomuto places pivot at its correct position and partitions smaller elements to left.
Predict Output
intermediate
2:00remaining
Output of Hoare Partition on Array
What is the output array after applying Hoare partition on the array [5, 1, 4, 2, 8] with pivot as first element?
DSA Javascript
function hoarePartition(arr, low, high) {
  let pivot = arr[low];
  let i = low - 1;
  let j = high + 1;
  while (true) {
    do {
      i++;
    } while (arr[i] < pivot);
    do {
      j--;
    } while (arr[j] > pivot);
    if (i >= j) return arr;
    [arr[i], arr[j]] = [arr[j], arr[i]];
  }
}

const arr = [5, 1, 4, 2, 8];
hoarePartition(arr, 0, arr.length - 1);
console.log(arr);
A[5, 1, 4, 2, 8]
B[2, 1, 4, 5, 8]
C[1, 2, 4, 5, 8]
D[4, 1, 2, 5, 8]
Attempts:
2 left
💡 Hint
Hoare partition swaps elements around pivot until pointers cross.
🧠 Conceptual
advanced
1:30remaining
Difference Between Lomuto and Hoare Partition
Which statement correctly describes a key difference between Lomuto and Hoare partition schemes?
ALomuto partition places pivot at its final position after partition, Hoare may not.
BHoare partition always places pivot at its final sorted position, Lomuto does not.
CLomuto partition uses two pointers moving inward, Hoare uses one pointer moving forward.
DHoare partition uses the last element as pivot, Lomuto uses the first element.
Attempts:
2 left
💡 Hint
Think about where the pivot ends after partition in each scheme.
🔧 Debug
advanced
2:00remaining
Identify the Bug in Lomuto Partition Code
What error will this Lomuto partition code produce when run on array [4, 9, 3, 7]? function lomutoPartition(arr, low, high) { let pivot = arr[high]; let i = low; for (let j = low; j < high; j++) { if (arr[j] <= pivot) { [arr[i], arr[j]] = [arr[j], arr[i]]; i++; } } [arr[i], arr[high]] = [arr[high], arr[i]]; return i; }
ANo error; returns correct pivot index
BTypeError due to invalid swap syntax
COff-by-one error causing incorrect pivot placement
DInfinite loop due to wrong loop condition
Attempts:
2 left
💡 Hint
Check initial value of i and how it affects swaps.
🚀 Application
expert
2:30remaining
Number of Items Left of Pivot After Hoare Partition
Given array [10, 7, 8, 9, 1, 5] and pivot as first element (10), after applying Hoare partition, how many elements are guaranteed to be on the left side of the pivot's final position?
AAll elements except pivot are on left
BAt least one element less than or equal to pivot is on left
CNo elements are guaranteed on left side
DExactly half of the elements are on left side
Attempts:
2 left
💡 Hint
Hoare partition rearranges but pivot may not be at final position.