A leaf has an equal probability of being 1
to k
in size.
Thus, the expected sheet size is k/2
.
If the expected leaf size is k/2
, then we expect n/(k/2)=(2n)/k
such leaves.
For simplicity, suppose we expect n/k
such leaves and that the expected size of each leaf is k
.
The expected INSERTION-SORT
is O(n^2)
.
We found that in exercise 5.2-5 and problem 2-4c.
Thus, the expected operating time of INSERTION-SORT
is O((n/k)*(k^2))=O(nk)
.
If we expect our partition groups to be of size k
, then it is expected that the height of the recursion tree will be lgn-lgk=lg(n/k)
, since we expect that we will stop at lgk
.
At each level of the recursion tree, there are O(n)
operations.
This brings us to O(nlg(n/k))
.
We conclude that the expected runtime is O(nk+nlg(n/k))
.
In theory, we should choose k=lgn
, since in this way we get the best expected run time O(nlgn)
.
In practice, we should choose k
for one of the values ββnear lgn
, which gives us better performance than just running RANDOMIZED-QUICKSORT
.
The second part of the answer uses the note of large o-output rather freely, so for a more accurate choice of k
, please follow the link provided in the second answer of Ankush.
source share