Step 1: Lomuto: set pivot=4, i=-1, j=0 start scanning
Array: [7, 2, 1, 6, 8, 5, 3, 4]
i=-1, j=0
Why: Initialize i before start to track smaller elements
Step 2: Lomuto: j=0 value 7 > pivot 4, no swap, j++
Array: [7, 2, 1, 6, 8, 5, 3, 4]
i=-1, j=1
Why: 7 is bigger than pivot, so leave it on right side
Step 3: Lomuto: j=1 value 2 < pivot 4, i=0, swap arr[i] and arr[j]
Array: [2, 7, 1, 6, 8, 5, 3, 4]
i=0, j=1
Why: 2 is smaller, move it left by swapping with element at i
Step 4: Lomuto: j=2 value 1 < pivot 4, i=1, swap arr[i] and arr[j]
Array: [2, 1, 7, 6, 8, 5, 3, 4]
i=1, j=2
Why: 1 is smaller, move it left
Step 5: Lomuto: j=3 value 6 > pivot 4, no swap, j++
Array: [2, 1, 7, 6, 8, 5, 3, 4]
i=1, j=3
Why: 6 bigger than pivot, keep right
Step 6: Lomuto: j=4 value 8 > pivot 4, no swap, j++
Array: [2, 1, 7, 6, 8, 5, 3, 4]
i=1, j=4
Why: 8 bigger than pivot, keep right
Step 7: Lomuto: j=5 value 5 > pivot 4, no swap, j++
Array: [2, 1, 7, 6, 8, 5, 3, 4]
i=1, j=5
Why: 5 bigger than pivot, keep right
Step 8: Lomuto: j=6 value 3 < pivot 4, i=2, swap arr[i] and arr[j]
Array: [2, 1, 3, 6, 8, 5, 7, 4]
i=2, j=6
Why: 3 smaller, move left
Step 9: Lomuto: end of loop, swap arr[i+1=3] with pivot at high=7
Array: [2, 1, 3, 4, 8, 5, 7, 6]
final pivot index=3
Why: Place pivot after smaller elements
Step 10: Hoare: set pivot=4 (arr[7]), i=0, j=7
Array: [7, 2, 1, 6, 8, 5, 3, 4]
i=0, j=7
Why: Initialize pointers at bounds
Step 11: i moves right while arr[i]<pivot; j moves left while arr[j]>pivot
Array: [7, 2, 1, 6, 8, 5, 3, 4]
i=0, j=7
Why: Find first i >= pivot and first j <= pivot
Step 12: i=0 < j=7, swap arr[0]↔arr[7]
Array: [4, 2, 1, 6, 8, 5, 3, 7]
i=0, j=7
Why: Swap out-of-place elements
Step 13: i moves right past 2,1; stops at 6; j moves left past 3; stops at 3
Array: [4, 2, 1, 6, 8, 5, 3, 7]
i=3, j=6
Why: Move pointers past elements in place
Step 14: i=3 < j=6, swap arr[3]↔arr[6]
Array: [4, 2, 1, 3, 8, 5, 6, 7]
i=3, j=6
Why: Swap 6 (>pivot) and 3 (<pivot)
Step 15: i moves right stops at 8; j moves left stops at 3; pointers crossed
Array: [4, 2, 1, 3, 8, 5, 6, 7]
i=4, j=3
Why: Continue moving until cross
Step 16: i >= j, return partition index j=3
Array: [4, 2, 1, 3, 8, 5, 6, 7]
Why: Pointers crossed, partition complete
Result: Lomuto partitioned array: [2, 1, 3, 4, 8, 5, 7, 6]
Pivot index: 3
Hoare partitioned array: [4, 2, 1, 3, 8, 5, 6, 7]
Partition index: 3