Step 1: Lomuto: choose last element 2 as pivot, start i at -1, j at 0
[5, 3, 8, 4, 2]
i = -1, j = 0, pivot = 2
Why: Pivot chosen at end; i tracks smaller elements boundary
Step 2: Lomuto: j=0 (5) > pivot(2), no swap, j moves to 1
[5, 3, 8, 4, 2]
i = -1, j = 1
Why: 5 is bigger than pivot, so it stays right
Step 3: Lomuto: j=1 (3) > pivot(2), no swap, j moves to 2
[5, 3, 8, 4, 2]
i = -1, j = 2
Why: 3 is bigger than pivot, stays right
Step 4: Lomuto: j=2 (8) > pivot(2), no swap, j moves to 3
[5, 3, 8, 4, 2]
i = -1, j = 3
Why: 8 bigger than pivot, stays right
Step 5: Lomuto: j=3 (4) > pivot(2), no swap, j moves to 4
[5, 3, 8, 4, 2]
i = -1, j = 4
Why: 4 bigger than pivot, stays right
Step 6: Lomuto: j reached end, swap pivot(2) with element at i+1 (index 0)
[2, 3, 8, 4, 5]
i = 0, pivot index = 0
Why: Place pivot in correct position after smaller elements
Step 7: Hoare: choose pivot as first element 5, left=0, right=4
[5, 3, 8, 4, 2]
left=0, right=4, pivot=5
Why: Pivot chosen at start; pointers move inward
Step 8: Hoare: move right pointer left while arr[right] > pivot: arr[4]=2 <=5 stop
[5, 3, 8, 4, 2]
left=0, right=4
Why: Find element smaller or equal to pivot from right
Step 9: Hoare: move left pointer right while arr[left] < pivot: arr[0]=5 not <5 stop
[5, 3, 8, 4, 2]
left=0, right=4
Why: Find element bigger or equal to pivot from left
Step 10: Hoare: left(0) < right(4), swap arr[left] and arr[right]
[2, 3, 8, 4, 5]
left=0, right=4
Why: Swap to put smaller on left and bigger on right
Step 11: Hoare: increment left to 1, decrement right to 3
[2, 3, 8, 4, 5]
left=1, right=3
Why: Move pointers inward to continue partition
Step 12: Hoare: move right pointer left while arr[right] > pivot: arr[3]=4 <5 stop
[2, 3, 8, 4, 5]
left=1, right=3
Why: Find element smaller or equal to pivot from right
Step 13: Hoare: move left pointer right while arr[left] < pivot: arr[1]=3 <5 left=2; arr[2]=8 >5 stop
[2, 3, 8, 4, 5]
left=2, right=3
Why: Find element bigger or equal to pivot from left
Step 14: Hoare: left(2) < right(3), swap arr[left] and arr[right]
[2, 3, 4, 8, 5]
left=2, right=3
Why: Swap to put smaller on left and bigger on right
Step 15: Hoare: increment left to 3, decrement right to 2
[2, 3, 4, 8, 5]
left=3, right=2
Why: Pointers crossed, partition done
Result: Lomuto partition result: [2, 3, 8, 4, 5], pivot index = 0
Hoare partition result: [2, 3, 4, 8, 5], partition index between 2 and 3