Here is the algorithm in pseudo code:
Where $A$ is the array to search, $p$ is the starting index in the array, $r$ is the ending index and $i$ represent the number of smaller values we want from our goal value, the $i$ smallest number in the array.
I dont understand the $k$.
It gets a value that dont realy represent the index of the value in the original array, but the index value in the sub array we are at, at the recursion process.
Similarly, it doesnt represent the amount of values that are smaller than the pivot we are at, but the number of smaller values in the current sub array in the recursive process.
So how can we check between $i$ and $k$? They dont talk on the same arrays...
Thank you.