knavely
01-27-2002, 09:37 PM
well im asked here to find a recurance for the worst case running time of this horrable "sorting algorythm"
anyway i found a recurance relation for the number of times the function is called
T(n) = T(n - floor(n/3) ) + 1
but im not sure where to go from here:
this is the algorythm:
void stoogeSort( int A[], int low, int high)
{
int third;
if( low + 1 ==high )
{
if( A[low ] > A[ high ] )
swap( A[ low ], A[ high ] );
}
else if (low + 1 < high )
{
third = (high - low + 1)/3;
stoogeSort(A, low, high-third);
stoogeSort(A, low+third, high);
stoogeSort(A, low, high-third);
}
}
:rolleyes:
any help would be sooooooo awsome.
anyway i found a recurance relation for the number of times the function is called
T(n) = T(n - floor(n/3) ) + 1
but im not sure where to go from here:
this is the algorythm:
void stoogeSort( int A[], int low, int high)
{
int third;
if( low + 1 ==high )
{
if( A[low ] > A[ high ] )
swap( A[ low ], A[ high ] );
}
else if (low + 1 < high )
{
third = (high - low + 1)/3;
stoogeSort(A, low, high-third);
stoogeSort(A, low+third, high);
stoogeSort(A, low, high-third);
}
}
:rolleyes:
any help would be sooooooo awsome.