Step 1: Lomuto: set pivot=2 (last element), i=-1, j=0 scans
[5, 3, 8, 4, 2]
i=-1, j=0, pivot=2
Why: Initialize pointers to start partitioning
Step 2: Lomuto: j=0 value=5 > pivot, no swap, i stays -1
[5, 3, 8, 4, 2]
i=-1, j=0
Why: 5 is bigger than pivot, keep i to separate smaller values
Step 3: Lomuto: j=1 value=3 > pivot, no swap, i stays -1
[5, 3, 8, 4, 2]
i=-1, j=1
Why: 3 is bigger than pivot, no change
Step 4: Lomuto: j=2 value=8 > pivot, no swap, i stays -1
[5, 3, 8, 4, 2]
i=-1, j=2
Why: 8 is bigger than pivot, no change
Step 5: Lomuto: j=3 value=4 > pivot, no swap, i stays -1
[5, 3, 8, 4, 2]
i=-1, j=3
Why: 4 is bigger than pivot, no change
Step 6: Lomuto: swap pivot with element at i+1 (index 0), swap 2 and 5
[2, 3, 8, 4, 5]
i=0
Why: Place pivot in correct position separating smaller and bigger
Step 7: Hoare: set pivot=5 (first element), i=0, j=4
[5, 3, 8, 4, 2]
i=0, j=4, pivot=5
Why: Initialize pointers for Hoare partition
Step 8: Hoare: move j left until element <= pivot; j=4 value=2 <=5 stop
[5, 3, 8, 4, 2]
i=0, j=4
Why: Find element on right smaller than pivot to swap
Step 9: Hoare: move i right until element >= pivot; i=0 value=5 >=5 stop
[5, 3, 8, 4, 2]
i=0, j=4
Why: Find element on left bigger than pivot to swap
Step 10: Hoare: swap elements at i=0 and j=4 (5 and 2)
[2, 3, 8, 4, 5]
i=0, j=4
Why: Swap out-of-place elements
Step 11: Hoare: increment i=1, decrement j=3
[2, 3, 8, 4, 5]
i=1, j=3
Why: Move pointers inward to continue partition
Step 12: Hoare: move j left until element <= pivot; j=3 value=4 <=5 stop
[2, 3, 8, 4, 5]
i=1, j=3
Why: Find next element on right smaller than pivot
Step 13: Hoare: move i right until element >= pivot; i=2 value=8 >=5 stop
[2, 3, 8, 4, 5]
i=2, j=3
Why: Find next element on left bigger than pivot
Step 14: Hoare: swap elements at i=2 and j=3 (8 and 4)
[2, 3, 4, 8, 5]
i=2, j=3
Why: Swap out-of-place elements
Step 15: Hoare: increment i=3, decrement j=2; now i > j stop
[2, 3, 4, 8, 5]
i=3, j=2
Why: Pointers crossed, partition done
Result: Lomuto partitioned array: [2, 3, 8, 4, 5]
Hoare partitioned array: [2, 3, 4, 8, 5]