Step 1: Lomuto: choose pivot = last element (2), 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 boundary of smaller elements
Step 2: Lomuto: j=0 (5) > pivot, no swap, i stays -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, no swap, i stays -1
[5, 3, 8, 4, 2]
i = -1, j = 2
Why: 3 is bigger than pivot, stays right
Step 4: Lomuto: j=2 (8) > pivot, no swap, i stays -1
[5, 3, 8, 4, 2]
i = -1, j = 3
Why: 8 is bigger than pivot, stays right
Step 5: Lomuto: j=3 (4) > pivot, no swap, i stays -1
[5, 3, 8, 4, 2]
i = -1, j = 4
Why: 4 is bigger than pivot, stays right
Step 6: Lomuto: swap pivot (2) with element at i+1 (5)
[2, 3, 8, 4, 5]
i = 0
Why: Place pivot in correct position, all left smaller or equal
Step 7: Hoare: choose pivot = first element (5), i=0, j=4
[5, 3, 8, 4, 2]
i=0, j=4, pivot=5
Why: Pivot chosen at start; i and j move inward
Step 8: Hoare: move j left while arr[j] > pivot: j=4 (2) ≤ 5 stop
[5, 3, 8, 4, 2]
i=0, j=4
Why: Find element smaller or equal to pivot from right
Step 9: Hoare: move i right while arr[i] < pivot: i=0 (5) not < 5 stop
[5, 3, 8, 4, 2]
i=0, j=4
Why: Find element bigger or equal to pivot from left
Step 10: Hoare: swap arr[i] (5) and arr[j] (2), i=1, j=3
[2, 3, 8, 4, 5]
i=1, j=3
Why: Swap to put smaller left and bigger right
Step 11: Hoare: move j left while arr[j] > pivot: j=3 (4) ≤ 5 stop
[2, 3, 8, 4, 5]
i=1, j=3
Why: Find next smaller or equal from right
Step 12: Hoare: move i right while arr[i] < pivot: i=1 (3) < 5 i=2 (8) not < 5 stop
[2, 3, 8, 4, 5]
i=2, j=3
Why: Find next bigger or equal from left
Step 13: Hoare: swap arr[i] (8) and arr[j] (4), i=3, j=2
[2, 3, 4, 8, 5]
i=3, j=2
Why: Swap to correct sides
Step 14: Hoare: i (3) > j (2), partition ends, return j=2
[2, 3, 4, 8, 5]
Why: Pointers crossed, partition done
Result: Lomuto partitioned array: [2, 3, 8, 4, 5]
Pivot index: 0
Hoare partitioned array: [2, 3, 4, 8, 5]
Partition index: 2