Sorting and Selecting (TODO)
Sorting and Selecting (TODO)
QuickSort
/Untitled.png)
Claim
Let be the (random) number of comparisons that are performed per call of , where is an array of pairwise different numbers. Then it holds that
Proof
For it holds that . For it follows that
Looking at this expression more closely we can find that the expected value does not actually depend on and , but much rather only from the amount of elements to sort . We can thus recursively define numbers :
By induction on we can easily see that for all the equality holds. Let’s determine an upper bound for . For all it holds according to above definition that
as well as
If we subtract the second from the first equation we get:
and therefore f
By induction over we can show that for all that
For it follows from the definition of , that . For we can use the inequality that we derived above together with the induction hypothesis.
Since it holds in particular that
This proves the claim.
QuickSelect
/Untitled%201.png)
Claim
We can find the -th least element in a sequence of elements in using the above algorithm, where is an array of pairwise different numbers.