My professor stated that the best case for quicksort is when the split is balanced (i.e. when the pivot is always the element in the middle).
Now the complexity of best-case quicksort can be determined by using a recurrent relation, as folows:
T(n) = 2*T(n/2) + partitioning(n)
In the next step he states:
thus = ~n * log2(n)
Could someone elaborate how exactly you can calculate this. I've searched around a lot, but all explanations are in big-Oh notation or don't really explain how the recurrency is solved/calculated.
I am going to address Tilde Notation in this answer, with the assumption of
partitioning(n)
is itself~n
, which means it runs in timeG(n) = n + C
.In this case, complexity function of best case is:
With base clause of
T(1) = 1+C
Claim: For all
n>0
:Proof by induction.
Base clause: For
T(1)
the claim holds as the base.Since
T(n) = nlogn + (2C+1)n - C
, we can conclude it is indeed~nlogn
.