Step 1: Lomuto: choose last element 2 as pivot, start i at -1, j at 0
Array: [5, 3, 8, 4, 2]
i = -1, j = 0, pivot = 2
Why: We pick pivot at end and prepare pointers to rearrange smaller elements left
Step 2: Lomuto: j=0 (5) > pivot(2), no swap, j moves to 1
Array: [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
Array: [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
Array: [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
Array: [5, 3, 8, 4, 2]
i = -1, j = 4
Why: 4 bigger than pivot, stays right
Step 6: Lomuto: swap pivot(2) with element at i+1 (index 0)
Array: [2, 3, 8, 4, 5]
i = 0
Why: Place pivot in correct position so left are smaller or equal
Step 7: Hoare: choose pivot as first element 5, i=0, j=4
Array: [5, 3, 8, 4, 2]
i = 0, j = 4, pivot = 5
Why: Pivot chosen at start, pointers ready to move inward
Step 8: Hoare: move i right while arr[i] < pivot: i=1 (3 < 5), i=2 (8 > 5 stop)
Array: [5, 3, 8, 4, 2]
i = 2, j = 4
Why: i stops at first element not less than pivot
Step 9: Hoare: move j left while arr[j] > pivot: j=4 (2 < 5 stop)
Array: [5, 3, 8, 4, 2]
i = 2, j = 4
Why: j stops at first element not greater than pivot
Step 10: Hoare: swap arr[i](8) and arr[j](2)
Array: [5, 3, 2, 4, 8]
i = 2, j = 4
Why: Swap to put smaller on left and bigger on right
Step 11: Hoare: move i right while arr[i] < pivot: i=3 (4 < 5), i=4 (8 > 5 stop)
Array: [5, 3, 2, 4, 8]
i = 4, j = 4
Why: i moves to next element not less than pivot
Step 12: Hoare: move j left while arr[j] > pivot: j=3 (4 < 5 stop)
Array: [5, 3, 2, 4, 8]
i = 4, j = 3
Why: j moves to next element not greater than pivot
Step 13: Hoare: since i >= j, partition ends, return j=3
Array: [5, 3, 2, 4, 8]
Why: Pointers crossed, partition done
Result: Lomuto partitioned array: [2, 3, 8, 4, 5] with pivot index 0
Hoare partitioned array: [5, 3, 2, 4, 8] with partition index 3