Complete the code to select the pivot element in Lomuto partition.
let pivot = arr[[1]];In Lomuto partition, the pivot is usually chosen as the last element, which is at index high.
Complete the code to swap elements during Lomuto partition when element is less than pivot.
arr.swap(i, [1]);j.low or high incorrectly.We swap the element at index i with the element at index j when the element at j is less than the pivot.
Fix the error in the Hoare partition loop condition to avoid infinite loop.
while arr[[1]] < pivot { i += 1; }
j instead of i in the forward scanning loop.low or high incorrectly.In Hoare partition, the index i moves forward while elements are less than the pivot.
Fill both blanks to complete the Hoare partition swap and loop break condition.
if i >= j { return j; } else { arr.[1](i, [2]); }
partition.We swap elements at indices i and j using swap. The loop breaks when i >= j.
Fill all three blanks to complete the Lomuto partition function return and swap.
arr.swap(i + 1, [1]); return [2] + 1; // pivot index is [3]
We swap the element at i + 1 with the pivot at high. Then return i + 1 as the pivot index.
