- #1
evinda
Gold Member
MHB
- 3,836
- 0
Hello! (Wave)
I am looking at the algorithm of the Quicksort:
According to my notes,the cost is: $T(n)=T(q)+T(n-q)+(\text{ cost of partition })$.
Why is it like that and not $T(n)=T(q-1)+T(n-q)+(\text{ cost of partition })$ ? (Thinking)
Also,how do we conclude that the cost of the worst case is $T(n)=T(n-1)+ \Theta(n)$ ? (Thinking)
I am looking at the algorithm of the Quicksort:
Code:
Quicksort(A,p,r)
if p<r then
q<-partition(A,p,r)
Quicksort(A,p,q-1)
Quicksort(A,q+1,r)
According to my notes,the cost is: $T(n)=T(q)+T(n-q)+(\text{ cost of partition })$.
Why is it like that and not $T(n)=T(q-1)+T(n-q)+(\text{ cost of partition })$ ? (Thinking)
Also,how do we conclude that the cost of the worst case is $T(n)=T(n-1)+ \Theta(n)$ ? (Thinking)