Kakkot SortKakkot Sort
is a sorting algorithm that ,makes O ( n log n ) (Big Oh notation)comparisons to sort n items. Typically,
is significantly faster inpractice than other O ( n log n ) algorithms ,because its inner loop can be efficientlyimplemented on most architectures . Thissorting method requires data movement butless than that of insertion sort. This datamovement can be reduced by implementingthe algorithm using linked list. Majoradvantage of this sorting method is itsbehavior pattern is same for all cases, ietime complexity of this method is same forbest, average and worst case
How it sorts
From the given set of unsorted numbers,take the first two numbers and name it askey one and key two , ie, K1 and K2. Readall the remaining numbers one by one.Compare each number first with K2. If thenumber is greater than or equal to K2 thenplace the number right of K2 else comparethe same number with K1. If the number isgreater than K1 then place the numberimmediate right of K1 else left of K1.Conitnue the same process for all theremaining numbers in the list. Finally wewill get three sub lists. One with numbersless than or equal to K1, one with numbersgreater than or equal to K2 and the otherwith numbers between K1 and K2. Repeatthe same process for each sub list. Continuethis process till the sub list contains zeroelements or one element.
(N:Array of Numbers, K1 ,K2 ,A:integers,)Step1. Read the first two numbers from N,Let K1 & K2Step2. Sort K1 and K2Step3. Read the next number, Let AStep4. Compare A with K2Step5. If A is greater than or equal to K2then place A right of K2elsecompare A with K1.If A is less than K1then place A left of K1elsePlace A immediate right of K1Step6 . If the list contains any moreelements go to step 3Step 7. Now we have 3 Sub list.
First list with all values lessthan or equal to K1.
Second with values betweenK1 and K2
Final with values greater thanor equal to K2.Step8. If each list contains more than 1element go to step1Step 9 End.
If there are ‘n’ numbers, then each iteration
needs maximum 2 * (n-2) comparison andminimum of n-2 comparison and plus one.So if we take the average it will be=(2n-4+n-2)/2 + 1=(3n-6)/2+1= 3n/2
2In the average case each list would have 3sub lists and number of iteration will be3
=ntaking logarithm on bothside we get
(IJCSIS) International Journal of Computer Science and Information Security,Vol. 8, No. 8, November 2010152 http://sites.google.com/site/ijcsis/ISSN 1947-5500