Question: Give the precise function for the worst case complexity of the given quickSort algorithm, methods are separeted with a line break, quicksort is the primary
Give the precise function for the worst case complexity of the given quickSort algorithm, methods are separeted with a line break, quicksort is the primary method.
void quickSort( Element[] E, int first, int last)
if(first < last){
Element pivotElement = E[first];
Key pivot = pivotElement.key;
int splitPoint = partition(E, pivot, first, last);
E[splitPoint] = pivotElement;
quickSort(E, first, splitPoint - 1);
quickSort(E, splitPoint+1, last);
return;
}
int partition( Element[] E, Key pivot, int first, int last) {
int low, high;
low = first; high = last;
while( low < high){
int highVac = extendLargeRegion(E, pivot, low, high);
int lowVac = extendSmallRegion(E,pivot, low + 1, highVac)
low = lowVac; high = highVac - 1;
return low; // this is the splitpoint
}
extendLargeRegion( Element[] E, Key pivot, int lowVac, int high){
int highVac, curr;
highVac = lowVac;// assume failure
curr = high;
while(curr > lowVac)
if( E[curr].key < pivot){
E[lowVac = E[curr]; // succeed
highVac = curr;
break;
}
curr-- // keep looking
return highVac;
}
int extendSmallRegion( Element[] E, Key pivot, int low, int highVac){
int lowVac, curr;
lowVac = highVac // assume failure
curr = low;
while(curr < highVac){
if (E[curr].key >= pivot)
E[highVac] = E[curr]; // succeed
lowVac = curr;
break;
}
curr+
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
