Given input array: 12 18 17 11 13 15 16 14
Pivot is 15.
Question: How many elements be at correct position after first partition?
The sequence I got after first partition 12 14 13 11 15 18 16 17
1. select any element a[k] as pivot where L<=K<=U
L=lower bound of the array
U=upper bound of the array
2. Hide pivot element at A[U] by swapping A[k] and A[U]
3. let i=L and j=U-1
4. Run loop for i as follows
5. Run loop for j as follows
6. Exchange A[i] and A[j]
7. Repeatedly do the above steps till i and j cross each other.
8. Swap the pivot element with A[i] after i and j crosses
9. Divide the array at pivot
Now my doubt is if I apply the algorithm presented in Coreman book the sequence I got is different. However in Coreman book it is assumed that the pivot is first element.
What to follow in such question???