This action might not be possible to undo. Are you sure you want to continue?

8, November 2010

**A Comparative Study on Kakkot Sort and Other Sorting Methods
**

Rajesh Ramachandran

HOD, Department of Computer Science Naipunnya Institute of Management & Information Technology, Pongam, Kerala Email: ryanrajesh@hotmail.com

Dr.E.Kirubakaran

Sr.DGM(Outsourcing),BHEL,Trichy Email: e_kiru@yahoo.com

Abstract: Several efficient algorithms were developed to cope with the popular task of sorting. Kakkot sort is a new variant of Quick and Insertion sort. The Kakkot sort algorithm requires O( n log n ) comparisons for worst case and average case. Typically, Kakkot Sort is significantly faster in practice than other O ( n log n ) algorithms , because its inner loop can be efficiently implemented on most architectures . This sorting method requires data movement, but less than that of insertion sort. This data movement can be reduced by implementing the algorithm using linked list. In this comparative study the mathematical results of Kakkot sort were verified experimentally on ten randomly generated unsorted numbers. To have some experimental data to sustain this comparison four different sorting methods were chosen and code was executed and execution time was noted to verify and analyze the performance. The Kakkot Sort algorithm performance was found better as compared to other sorting methods. Key words: Complexity, performance of algorithms, sorting

Introduction Sorting is any process of arranging items in some sequence and/or in different sets, and accordingly, it has two common, yet distinct meanings: 1. ordering: arranging items of the same kind, class, nature, etc. in some ordered sequence, 2. categorizing: grouping and labeling items with similar properties together (by sorts). In computer science and mathematics, a Sorting Algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. Efficient sorting is important to optimizing the use of other algorithms (such as search and merge algorithms) that require sorted lists to work correctly. To analyze an algorithm is to determine the amount of resources (such as time and storage) necessary to execute it. Most algorithms are designed to work with inputs of arbitrary length. Usually the efficiency or complexity of an algorithm is stated as a function relating the input length to the number of steps (time complexity) or storage locations (space complexity). Algorithm analysis is an important part of a broader computational complexity theory,

150

http://sites.google.com/site/ijcsis/ ISSN 1947-5500

(IJCSIS) International Journal of Computer Science and Information Security, Vol. 8, No. 8, November 2010

which provides theoretical estimates for the resources needed by any algorithm which solves a given computational problem. These estimates provide an insight into reasonable directions of search for efficient algorithms. In theoretical analysis of algorithms it is common to estimate their complexity in the asymptotic sense, i.e., to estimate the complexity function for arbitrarily large input. Big O notation, omega notation and theta notation are used to this end Time complexity Time efficiency estimates depend on what we define to be a step. For the analysis to correspond usefully to the actual execution time, the time required to perform a step must be guaranteed to be bounded above by a constant. In mathematics, computer science, and related fields, Big Oh notation describes the limiting behavior of a function when the argument tends towards a particular value or infinity, usually in terms of simpler functions. Big O notation allows its users to simplify functions in order to concentrate on their growth rates: different functions with the same growth rate may be represented using the same O notation. Although developed as a part of pure mathematics, this notation is now frequently also used in computational complexity theory to describe an algorithm's usage of computational resources: the worst case or average case running time or memory usage of an algorithm is often expressed as a function of the length of its input using big O notation. Space complexity The better the time complexity of an algorithm is, the faster the algorithm will carry out his work in practice. Apart from

time complexity, its space complexity is also important: This is essentially the number of memory cells which an algorithm needs. A good algorithm keeps this number as small as possible, too. The space complexity of a program (for a given input) is the number of elementary objects that this program needs to store during its execution. This number is computed with respect to the size n of the input data. There is often a time-space-tradeoff involved in a problem, that is, it cannot be solved with few computing time and low memory consumption. One then has to make a compromise and to exchange computing time for memory consumption or vice versa, depending on which algorithm one chooses and how one parameterizes it. In addition to varying complexity, sorting algorithms also fall into two basic categories — comparison based and non-comparison based. A comparison based algorithm orders a sorting array by weighing the value of one element against the value of other elements. Algorithms such as Quicksort, Mergesort, Heapsort, Bubble sort, and Insertion sort are comparison based. Alternatively, a noncomparison based algorithm sorts an array without consideration of pairwise data elements. Radix sort is a non-comparison based algorithm that treats the sorting elements as numbers represented in a baseM number system, and then works with individual digits of M. Another factor which influences the performance of sorting method is the behavior pattern of the input. In computer science, best, worst and average cases of a given algorithm express what the resource usage is at least, at most and on average, respectively. Usually the resource being considered is running time, but it could also be memory or other resources.

151

http://sites.google.com/site/ijcsis/ ISSN 1947-5500

(IJCSIS) International Journal of Computer Science and Information Security, Vol. 8, No. 8, November 2010

Kakkot Sort Kakkot Sort is a sorting algorithm that , makes O ( n log n ) (Big Oh notation) comparisons to sort n items. Typically, Kakkot Sort is significantly faster in practice than other O ( n log n ) algorithms , because its inner loop can be efficiently implemented on most architectures . This sorting method requires data movement but less than that of insertion sort. This data movement can be reduced by implementing the algorithm using linked list. Major advantage of this sorting method is its behavior pattern is same for all cases, ie time complexity of this method is same for best, average and worst case How it sorts From the given set of unsorted numbers, take the first two numbers and name it as key one and key two , ie, K1 and K2. Read all the remaining numbers one by one. Compare each number first with K2. If the number is greater than or equal to K2 then place the number right of K2 else compare the same number with K1. If the number is greater than K1 then place the number immediate right of K1 else left of K1.Conitnue the same process for all the remaining numbers in the list. Finally we will get three sub lists. One with numbers less than or equal to K1, one with numbers greater than or equal to K2 and the other with numbers between K1 and K2. Repeat the same process for each sub list. Continue this process till the sub list contains zero elements or one element.

Step1. Read the first two numbers from N, Let K1 & K2 Step2. Sort K1 and K2 Step3. Read the next number, Let A Step4. Compare A with K2 Step5. If A is greater than or equal to K2 then place A right of K2 else compare A with K1. If A is less than K1 then place A left of K1 else Place A immediate right of K1 Step6 . If the list contains any more elements go to step 3 Step 7. Now we have 3 Sub list. First list with all values less than or equal to K1. Second with values between K1 and K2 Final with values greater than or equal to K2. Step8. If each list contains more than 1 element go to step1 Step 9 End. Time complexity If there are ‘n’ numbers, then each iteration needs maximum 2 * (n-2) comparison and minimum 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 – 2 In the average case each list would have 3 sub lists and number of iteration will be 3x=n taking logarithm on both side we get

Algorithm Kakkot Sort(N:Array of Numbers, K1 ,K2 , A:integers,)

152

http://sites.google.com/site/ijcsis/ ISSN 1947-5500

(IJCSIS) International Journal of Computer Science and Information Security, Vol. 8, No. 8, November 2010

x log 3= log n x= log n / log 3 x= log n/ 0.4771 Ignoring the constant we can write x = log n That is there will be log n iterations and each require 3n/2 – 2 comparisons. So the time complexity of Kakkot Sort in average case is 3n/2 – 2 * log n. When we represent in Big Oh notation constants can be ignored, so we get O(n log n). If the list is already in sorted order, then two comparison will be required for each number ,so total no of comparison required for each iteration will be (n-2)+1, i.e. n-1 and number of iteration will be n-1+n-3+n6+…..+1 This can be written as 1+3+5+…..n-3+n-1. Sum of this series is S= N/2*(2a +(N-1)*d) Where N is the number of terms in the series ‘a’ is first term ‘d’ is the difference To get Nth term, the equation is a+(N-1) d And here Nth term is n- 1, so 1+(N-1)*2=n-1 2N=n N= n/2 S=N/2(2*1+(N-1)*2) S=N/2(2+2N-2) S=N/2(2N) Sum = N2 Substitute value for N we get (n/2)**2 This is equal to one forth of n2. So Kakkot Sort requires only one forth of Quick sort comparison in worst case. This is almost equal to average case time complexity. So we can say that time complexity of Kakkot sort is similar in all the cases. Now let me manually calculate the number of comparison that Kakkot sort take.

Consider the following randomly generated ten unsorted numbers 1,60,33,3,35,21,53,19,70,94 List 1 First two numbers are 1 and 60 and sort it . Here K1 is 1 and K2 is 60 Now the total comparison is one. Read the remaining numbers one by one Read 33, since 33 is less than K2 and greater than K1 it need two comparison . Now the total comparison is increased to 3. Read 3, total comparison is now 5 Read 35, total comparison is now 7 Read 21, total comparison is now 9 Read 53, total comparison now is 11 Read 19, total comparison now is 13 Read 70, total comparison now is 14 Read 94 total comparison now is 15 Now the list will be 1, 3,35,21,53,19 ,60,70,94 Here we have 3 sublist The first one with zero elements Second list is , 3,35, 35,21,53,19 Third list is 70,94 Now do the same process second and third list Second list Read first two numbers, and sort We have K1 =3 and K2= 35 Now total comparison is 16 Read 21, total comparison now is 18 Read 53,total comparison now is 19 Read 19,total comparison now is 21 Now the list will be 3,19,21,35,53 Now only one list with more than one element, ie 19 and 21 Read the first two numbers and sort Here K1=19 and K2 =21 Now the total comparison is 22 Now regarding the sublist 3 we have two numbers 70 and 94 Read the numbers and sort Now the total number of comparison is 23

153

http://sites.google.com/site/ijcsis/ ISSN 1947-5500

Kakkot Sort and Bubble Sort So Using Kakkot sort , to sort the given ten randomly generated numbers require only 23 comparisons. Kakkot Sort and Qucick Sort Time complexity of Quick sort is O(n log n) in the case of average case and O(n2) in the worst case behavior. From this it is clear that Kakkot sort is better than quick sort. While sorting Quick sort does not require any data movement where as Kakkot sort needs data movement when the item is less than first key element and greater than second key element. But this data movement can be avoided by implementing the algorithm using linked list. To sort the above ten numbers in the List 1 , Quick sort requires 29 comparisons Kakkot Sort and Heap Sort Heapsort is a much more efficient version of selection sort. It also works by determining the largest (or smallest) element of the list, placing that at the end (or beginning) of the list, then continuing with the rest of the list, but accomplishes this task efficiently by using a data structure called a heap, a special type of binary tree. Once the data list has been made into a heap, the root node is guaranteed to be the largest(or smallest) element. When it is removed and placed at the end of the list, the heap is rearranged so the largest element remaining moves to the root. Using the heap, finding the next largest element takes O(log n) time, instead of O(n) for a linear scan as in simple selection sort. This allows Heapsort to run in O(n log n) time, and this is also the worst case complexity. With the same set of unsorted numbers in the List 1, Heap sort requires 30 comparisons Bubble sort is a straightforward and simplistic method of sorting data that is used in computer science education. The algorithm starts at the beginning of the data set. It compares the first two elements, and if the first is greater than the second, then it swaps them. It continues doing this for each pair of adjacent elements to the end of the data set. It then starts again with the first two elements, repeating until no swaps have occurred on the last pass. This algorithm is highly inefficient, and is rarely used[citation needed][dubious – discuss], except as a simplistic example. For example, if we have 100 elements then the total number of comparisons will be 10000. A slightly better variant, cocktail sort, works by inverting the ordering criteria and the pass direction on alternating passes. The modified Bubble sort will stop 1 shorter each time through the loop, so the total number of comparisons for 100 elements will be 4950. Bubble sort average case and worst case are both O(n²) For the above unsorted numbers in the List 1 Bubble sort requires 45 comparisons.

Kakkot Sort and Insertion Sort Insertion sort is a simple sorting algorithm that is relatively efficient for small lists and mostly-sorted lists, and often is used as part of more sophisticated algorithms. It works by taking elements from the list one by one and inserting them in their correct position into a new sorted list. In arrays, the new list and the remaining elements can share the array's space, but insertion is expensive, requiring shifting all following elements over by one. Shell sort (see below) is a

154

http://sites.google.com/site/ijcsis/ ISSN 1947-5500

variant of insertion sort that is more efficient for larger lists. Insertion sort requires 38 comparisons to sort the above ten randomly generated numbers in the List 1.

[6] Sartaj Sahni, “Data Structures Algorithms and Applications in C++”, University Press, 2nd Ed.,2005 [7] Yedidyah Langsam,Moshe J Augenstein, Aaron M Tanenbaum “Data Structures using C and C++”, Prentice Hall India, 2nd Ed. 2005 [8] Alfred V Aho, John E Hopcroft, Jeffrey D Ullman,”Data Structures and Algorithms”, Pearson Education,2nd Ed.,2006 [9] Sara Baase, Allen Van Gelder, “Computer Algorithms Introduction to Design and Analysis, Pearson Education, 3rd Ed. ,2006 [10] Mark Allen Weiss “Data Structures and Algorithm analysis in C++ “, Pearson Education, 3rd Ed., 2007 [11] Michael T Goodrich, Roberto Tamassia, “Algorithm Design Foundations, Analysis and Internet Examples”, John Wiley and Sons Inc.,2007 [12] Seymour Lipschutz, GAV Pai , “ Data Structures”, Tata McGraw Hill,2007 [13] Robert Lafore,” Data Structures and Algorithms in Java”, Waite Group Inc., 2007 [14] Rajesh Ramachandran, Dr.E. Kirubakaran, “Kakkot Sort – A New Sorting Method”, International Journal of Computer Science, Systems Engineering and Information Technology, ISSN 0974-5807 Vol. 2 No. 2 pp209-213,2010

Conclusion From the above examples it is clear that Kakkot Sort time complexity is better than other sorting methods. Even though Kakkot sort requires data movement of items when the item is less than the key K2 and greater than the key K1, this data movement can be reduced by implementing the algorithm using linked list. References: [1] Aaron M Tanenbaum, Moshe J Augenstein, “Data Structures using C”,Prentice Hall International Inc.,Emglewood Cliffs,NJ,1986 [2] Robert L Cruse, “ Data Structure and Program Design”, Prentice Hall India 3rd ed.,1999 [3] Robert Kruse, C L Tondo, Bruse Leung “Data Structures and Program design in C”, Pearson Education,2nd Ed.,2002 [4] Alfred V Aho, John E Hopcroft, Jeffrey D Ullman, “ The Design and Analysis of Computer Alogorithms”, Pearson Education , 2003 [5] Thomas H Cormen, Charles E Leiserson, Ronald L Rivest, Clifford Stein, “Introduction to Algorithms” Prentice Hall of India Pvt.Ltd., 2nd Ed. , 2004

155

http://sites.google.com/site/ijcsis/ ISSN 1947-5500

- Journal of Computer Science IJCSIS March 2016 Part II
- Journal of Computer Science IJCSIS March 2016 Part I
- Journal of Computer Science IJCSIS April 2016 Part II
- Journal of Computer Science IJCSIS April 2016 Part I
- Journal of Computer Science IJCSIS February 2016
- Journal of Computer Science IJCSIS Special Issue February 2016
- Journal of Computer Science IJCSIS January 2016
- Journal of Computer Science IJCSIS December 2015
- Journal of Computer Science IJCSIS November 2015
- Journal of Computer Science IJCSIS October 2015
- Journal of Computer Science IJCSIS June 2015
- Journal of Computer Science IJCSIS July 2015
- International Journal of Computer Science IJCSIS September 2015
- Journal of Computer Science IJCSIS August 2015
- Journal of Computer Science IJCSIS April 2015
- Journal of Computer Science IJCSIS March 2015
- Fraudulent Electronic Transaction Detection Using Dynamic KDA Model
- Embedded Mobile Agent (EMA) for Distributed Information Retrieval
- A Survey
- Security Architecture with NAC using Crescent University as Case study
- An Analysis of Various Algorithms For Text Spam Classification and Clustering Using RapidMiner and Weka
- Unweighted Class Specific Soft Voting based ensemble of Extreme Learning Machine and its variant
- An Efficient Model to Automatically Find Index in Databases
- Base Station Radiation’s Optimization using Two Phase Shifting Dipoles
- Low Footprint Hybrid Finite Field Multiplier for Embedded Cryptography

Several efficient algorithms were developed to cope with the popular task of sorting. Kakkot sort is a new variant of Quick and Insertion sort. The Kakkot sort algorithm requires O( n log n ) compa...

Several efficient algorithms were developed to cope with the popular task of sorting. Kakkot sort is a new variant of Quick and Insertion sort. The Kakkot sort algorithm requires O( n log n ) comparisons for worst case and average case. Typically, Kakkot Sort is significantly faster in practice than other O ( n log n ) algorithms , because its inner loop can be efficiently implemented on most architectures . This sorting method requires data movement, but less than that of insertion sort. This data movement can be reduced by implementing the algorithm using linked list. In this comparative study the mathematical results of Kakkot sort were verified experimentally on ten randomly generated unsorted numbers. To have some experimental data to sustain this comparison four different sorting methods were chosen and code was executed and execution time was noted to verify and analyze the performance. The Kakkot Sort algorithm performance was found better as compared to other sorting methods.

- 8 Sorting
- Performance Comparison of Sorting Algorithms On The Basis Of Complexity-542.pdf
- 1.2 Comparing Algorithms2
- Selection of Best Sorting Algorithm
- 12593106731_2_1_ACR
- MIT Lectures (Awesome).pdf
- Intro Analysis
- Study of Sorting Algorithm to Optimize Search Results
- Freezing Sort
- Introduction.to.Algorithms
- Computer algorithms.pdf
- 1
- prog-assign-3-explained (1).pdf
- SortingSaad
- Sorting
- Review on Sorting Algorithms A Comparative Study
- 08 Algorithmic Analysis
- Introduction to Algorithm Complexity
- asymptotic
- Comparación de los Algoritmos de Busqueda.
- assignment.pdf
- C-Sorting
- [IJCST-V3I5P21]:Niharika Singh, DR. R. G. Tiwari
- 3-Divide and Conquer Approach
- asysmptotic behavious
- HW1_SolutionKey
- Design and Analysis of Algorithms
- Sorting Efficiency - Advance Programming Techniques - M70CDE
- algorithmComplexity in data structure
- Optimized Select Algo
- A Comparative Study on Kakkot Sort and Other Sorting Methods

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue reading from where you left off, or restart the preview.

scribd