Step 1: Lomuto: start with i = -1, j = 0; compare arr[j] with pivot 4
[7, 2, 1, 6, 8, 5, 3, 4], i = -1, j = 0
Why: We scan from left to right to find elements smaller than pivot
Step 2: Lomuto: arr[j]=7 > 4, no swap, j++
[7, 2, 1, 6, 8, 5, 3, 4], i = -1, j = 1
Why: 7 is bigger than pivot, so we skip
Step 3: Lomuto: arr[j]=2 < 4, increment i to 0, swap arr[i] and arr[j]
[2, 7, 1, 6, 8, 5, 3, 4], i = 0, j = 2
Why: 2 is smaller than pivot, move it to left side
Step 4: Lomuto: arr[j]=1 < 4, increment i to 1, swap arr[i] and arr[j]
[2, 1, 7, 6, 8, 5, 3, 4], i = 1, j = 3
Why: 1 is smaller than pivot, move it left
Step 5: Lomuto: arr[j]=6 > 4, no swap, j++
[2, 1, 7, 6, 8, 5, 3, 4], i = 1, j = 4
Why: 6 is bigger than pivot, skip
Step 6: Lomuto: arr[j]=8 > 4, no swap, j++
[2, 1, 7, 6, 8, 5, 3, 4], i = 1, j = 5
Why: 8 is bigger than pivot, skip
Step 7: Lomuto: arr[j]=5 > 4, no swap, j++
[2, 1, 7, 6, 8, 5, 3, 4], i = 1, j = 6
Why: 5 is bigger than pivot, skip
Step 8: Lomuto: arr[j]=3 < 4, increment i to 2, swap arr[i] and arr[j]
[2, 1, 3, 6, 8, 5, 7, 4], i = 2, j = 7
Why: 3 is smaller than pivot, move it left
Step 9: Lomuto: swap pivot arr[7] with arr[i+1] arr[3]
[2, 1, 3, 4, 8, 5, 7, 6]
Why: Place pivot in correct position
Step 10: Hoare: left=0, right=7, pivot=4; move left until arr[left]>=pivot
[7, 2, 1, 6, 8, 5, 3, 4], left=0, right=7
Why: Find element on left side that should be on right
Step 11: Hoare: arr[left]=7 >= 4 stop; move right until arr[right]<=pivot
[7, 2, 1, 6, 8, 5, 3, 4], left=0, right=7
Why: Find element on right side that should be on left
Step 12: Hoare: arr[right]=4 <= 4 stop; swap arr[left] and arr[right]
[4, 2, 1, 6, 8, 5, 3, 7], left=0, right=7
Why: Swap misplaced elements
Step 13: Hoare: increment left to 1; decrement right to 6
[4, 2, 1, 6, 8, 5, 3, 7], left=1, right=6
Step 14: Hoare: arr[left]=2 < 4 increment left to 2
[4, 2, 1, 6, 8, 5, 3, 7], left=2, right=6
Why: 2 is on correct side
Step 15: Hoare: arr[left]=1 < 4 increment left to 3
[4, 2, 1, 6, 8, 5, 3, 7], left=3, right=6
Why: 1 is on correct side
Step 16: Hoare: arr[left]=6 >= 4 stop; arr[right]=3 <= 4 stop; swap arr[left] and arr[right]
[4, 2, 1, 3, 8, 5, 6, 7], left=3, right=6
Why: Swap misplaced elements
Step 17: Hoare: increment left to 4; decrement right to 5
[4, 2, 1, 3, 8, 5, 6, 7], left=4, right=5
Step 18: Hoare: arr[left]=8 >= 4 stop; arr[right]=5 >= 4 decrement right to 4
[4, 2, 1, 3, 8, 5, 6, 7], left=4, right=4
Why: Find element on right side smaller than pivot
Step 19: Hoare: left >= right stop partitioning
[4, 2, 1, 3, 8, 5, 6, 7]
Result: Lomuto partitioned array: [2, 1, 3, 4, 8, 5, 7, 6]
Hoare partitioned array: [4, 2, 1, 3, 8, 5, 6, 7]