Being the recursion depth of the maximum number of consecutive recursive calls, before QuickSort gets the wink of the base case, and noting that it (the recursion depth) is a random variable because it depends on the selected axis.
I want to evaluate the minimum possible and maximum possible depth of QuickSort recursion.
The following procedure describes how QuickSort typically runs:
QUICKSORT(A,p,r) if p<r q β PARTITION(A,p,r) QUICKSORT(A,p,qβ1) QUICKSORT(A,q+1,r) return A PARTITION(A,p,r) xβA[r] iβpβ1 for j βp to rβ1 if A[j] β€ x i β i +1 exchange A[i] β A[j] exchange A[i +1] β A[r] return i +1
A second recursive call in QuickSort is not needed; it can be avoided by using an iterative control structure. This method is also called tail recursion, and can be implemented as follows:
QUICKSORT_tail(A,p,r) while p<r q β PARTITION(A,p,r) QUICKSORT(A,p,qβ1) p β q+1 return A
In this version, information for the most recent call is at the top of the stack, and information for the initial call is at the bottom. When a procedure is called, its information is pushed onto the stack; when it completes, its information pops up. Since I assume that the parameters of the array are represented by pointers, the information for each procedure call on the stack requires O (1) stack space. I also believe that the maximum possible stack space with this version should be & theta; (n).
So, after all this, how can I evaluate the minimum possible and maximum possible recursion depth of each version of QuickSort? Am I correct in the above conclusion?
Thanks in advance.