Step 1: Lomuto: choose last element 9 as pivot, start i at low-1 = -1
[7, 2, 5, 3, 9]
i = -1, j = 0
Why: We pick pivot at end and i tracks last smaller element
Step 2: Lomuto: j=0, 7 <= 9, increment i to 0, swap arr[i] and arr[j]
[7, 2, 5, 3, 9]
i = 0, j = 0
Why: 7 is smaller than pivot, so move it to left side
Step 3: Lomuto: j=1, 2 <= 9, increment i to 1, swap arr[i] and arr[j]
[7, 2, 5, 3, 9]
i = 1, j = 1
Why: 2 is smaller than pivot, keep it on left
Step 4: Lomuto: j=2, 5 <= 9, increment i to 2, swap arr[i] and arr[j]
[7, 2, 5, 3, 9]
i = 2, j = 2
Why: 5 is smaller than pivot, keep it on left
Step 5: Lomuto: j=3, 3 <= 9, increment i to 3, swap arr[i] and arr[j]
[7, 2, 5, 3, 9]
i = 3, j = 3
Why: 3 is smaller than pivot, keep it on left
Step 6: Lomuto: swap pivot arr[i+1] and arr[end], pivot stays at index 4
[7, 2, 5, 3, 9]
Pivot index = 4
Why: Place pivot after all smaller elements
Step 7: Hoare: choose pivot as first element 7, left = low - 1 = -1, right = high + 1 = 5
[7, 2, 5, 3, 9]
left=-1, right=5
Why: Pivot chosen at start, pointers initialized outside the array bounds
Step 8: Hoare: move right leftwards until arr[right] <= pivot: right-- from 5 to 4 (9 > 7), to 3 (3 <= 7)
[7, 2, 5, 3, 9]
left=-1, right=3
Why: Find the first element from right that is <= pivot
Step 9: Hoare: move left rightwards until arr[left] >= pivot: left++ from -1 to 0 (7 >= 7)
[7, 2, 5, 3, 9]
left=0, right=3
Why: Find the first element from left that is >= pivot
Step 10: Hoare: left < right, swap arr[left=0] and arr[right=3]: swap 7 and 3
[3, 2, 5, 7, 9]
left=0, right=3
Why: Swap elements that are on the wrong sides of pivot
Step 11: Hoare: move right leftwards until arr[right] <= pivot: right-- to 2 (5 <= 7)
[3, 2, 5, 7, 9]
left=0, right=2
Why: Continue scanning from right for next <= pivot
Step 12: Hoare: move left rightwards until arr[left] >= pivot: left++ to 1 (2 < 7), to 2 (5 < 7), to 3 (7 >= 7)
[3, 2, 5, 7, 9]
left=3, right=2
Why: Continue scanning from left for next >= pivot
Step 13: Hoare: left >= right, partition ends, return right index 2
[3, 2, 5, 7, 9]
Partition index = 2
Why: Pointers have crossed, partition complete
Result: Lomuto final: [7, 2, 5, 3, 9], pivot index 4
Hoare final: [3, 2, 5, 7, 9], partition index 2