I have found the following quicksort algorithm:
function quicksort(array)
less, equal, greater := three empty arrays
if length(array) > 1
pivot := select any element of array
for each x in array
if x < pivot then add x to less
if x = pivot then add x to equal
if x > pivot then add x to greater
quicksort(less)
quicksort(greater)
array := concatenate(less, equal, greater)
and I want to make its algorithm analysis by finding the recurrence relation. For what I see everytime that this algorithm is called, by choosing the pivot, for example, in the first position of the original array. It calls the quicksort again with the two generated lists, so I will have:
one list ------ pow(2,0)=1
less greater--------2 lists----pow(2,1)=2
less greater less greater-------4 lists---pow(2,2)=4
so it seems it forms a sort of binary tree, so if I get the pattern it will be: 2^k=n, where k is the levels of recursion, so I will have O(log n)
but how to do the same with analysis of recurrences? I mean, because I am not calculating the process of the de-stack of the function, something that happens in all recursive algorithms.
Any help? Thanks