
V.P.Kulalvaimozhi et al, International Journal of Computer Science and Mobile Computing, Vol.4 Issue.1, January- 2015, pg. 291-306 Available Online at www.ijcsmc.com International Journal of Computer Science and Mobile Computing A Monthly Journal of Computer Science and Information Technology ISSN 2320–088X IJCSMC, Vol. 4, Issue. 1, January 2015, pg.291 – 306 RESEARCH ARTICLE PERFORMANCE ANALYSIS OF SORTING ALGORITHM V.P.Kulalvaimozhi, M.Muthulakshmi, R.Mariselvi, G.Santhana Devi, C.Rajalakshmi & C. Durai Department of Computer Science, Kamarajar Govt. Arts College, Surandai – 627 859 *Corresponding Author: [email protected] ABSTRACT An algorithm is a sequence of steps that gives method of solving a problem. It creates the logic of program. As an algorithm is executed, it uses the computer’s Central Processing Unit (CPU) to perform operations and its memory to hold the program and data. Sorting means arranging the data in an orderly manner. The main objective is to compare the various sorting algorithms and these sorting algorithms are implemented by using a C++ program also the asymptotic complexity of each sorting algorithm is prepared. Keywords: Bubble sort, Insertion sort, Selection sort, Shell sort, Merge sort, Quick sort, Heap sort, Binary Tree sort, Address calculation sort, Radix sort. 1. INTRODUCTION Performance analysis refers to the task of determining how much computing time and storage an algorithm requires. The space complexity of a program is the amount of memory it needs to run to completion. The time complexity of a program is the amount of computer time it needs to run to completion. Sorting refers to the operation of arranging data in some given order, such as increasing or decreasing with numerical data or alphabetically with character data. All sorting algorithm apply to specific kind of problems. Some sorting algorithm apply to small number of elements, some sorting algorithm suitable for floating point numbers, some are fit for specific range like (0 1). Some sorting algorithm are used for large number of data, some are used for data with duplicate values. Performance evaluation can be loosely divided into two major phases: 1. Priori estimates 2. Posteriori estimates Simply we can refer these as performance analysis and performance measurement respectively. © 2015, IJCSMC All Rights Reserved 291 V.P.Kulalvaimozhi et al, International Journal of Computer Science and Mobile Computing, Vol.4 Issue.1, January- 2015, pg. 291-306 The complexity of a sorting algorithm measures the running time as a function of the number of n items to be sorted. Each sorting algorithm S will be made up of the following operations, where A1, A2,....An contain the items to be sorted and B is an auxiliary location. 1) Comparisons which test whether Ai<Aj or test whether Ai<B. 2) Interchanges which switch the contents of Ai and Aj or Ai and B. 3) Assignments which set B=Ai and then set Aj=B or Aj=Ai. Generally the complexity function measures only the number of comparisons, since the number of other operations is at most a constant factor of the number of other operations is at most a constant factor of the number of comparisons. Suppose space is fixed for one algorithm then only run time will be considered for obtaining the complexity of algorithm. We take 3 cases for complexity of algorithms. A) Best case B) Worst case C) Average case Best case: In this case, algorithm searches the element in first time itself. So taking this case for complexity of algorithm doesn’t tell too much. Let us take a case of linear search, if it finds the element at first time itself then it behaves as best case. Worst case: In this case, we find the element at the end or when searching of element fails. Suppose the element for which algorithm is searching is the last element of array or it’s not available in array then algorithm behaves as worst case. This case is necessary in the view that algorithm will perform at least up to this efficiency and it will not go for less than this efficiency. Average case: In this case, the average number of steps but since data can be at an place, so finding exact behavior of algorithm is difficult. As the volume of data increases average of algorithm behaves like worst case of algorithm. Analyzing the average case behavior of algorithm is little bit complex than best and worst case. 2. SORTING METHODS: The sorting methods can be divided into two parts. 1. Internal sorting method 2. External sorting method In an internal sorting method, data is going to be sorted will be in main memory. In an external sorting data will be on auxiliary storage like tape, floppy disk etc., 2.1. Bubble sort: In the bubble sort, the consecutive elements of the table are compared and if the keys of the two elements are not found in proper order, they are interchanged. It starts from the beginning of the table and continue till the end of the table. As a result of this the element with the largest key will be pushed to the last element’s position. After this the second pass is made.The second pass is exactly like the first one except that this time the elements except the last are considered. After © 2015, IJCSMC All Rights Reserved 292 V.P.Kulalvaimozhi et al, International Journal of Computer Science and Mobile Computing, Vol.4 Issue.1, January- 2015, pg. 291-306 the second pass, the next largest element will be pushed down to the next to last position. The second pass is followed by a third and so on until either (n-1) passes have been made or no interchange takes place in a pass. Here n is assumed to be the number of elements in the table. It may be noted that the non occurrence of any interchange in a pass ensures that the table is sorted. Ie, each number slowly bubbles up to its proper position. Ex; Consider the following numbers are stored in an array: Original Array : 32,51,27,85,66,23,13,57 Pass 1 : 32,27,51,66,23,13,57,85 Pass 2 : 27,33,51,23,13,57,66,85 Pass 3 : 27,33,23,13,51,57,66,85 Pass 4 : 27,23,13,33,51,57,66,85 Pass 5 : 23,13,27,33,51,57,66,85 Pass 6 : 13,23,27,33,51,57,66,85 Advantages: 1. Straightforward, simple and slow. 2. Stable. 3. Inefficient on large tables. 2.2. Insertion sort: An insertion sort is one that sorts a set of elements by inserting elements into an existing sorted array. Insertion sort uses the least CPU time, the smallest comparions and assignments. In this sort, ith pass we insert the ith element A[i] into its rightful place among A[1],A[2],….A[i-1] which were previously placed in sorted order. After doing this insertion, the elements occupying A[1],……A[i] are in sorted order. Ex; Consider the following numbers are stored in an array: Original Array : 77,33,44,11,88,22,66,55 Pass 1 : 33,77,44,11,88,22,66,55 Pass 2 : 33,44,77,11,88,22,66,55 Pass 3 : 11,33,44,77,88,22,66,55 © 2015, IJCSMC All Rights Reserved 293 V.P.Kulalvaimozhi et al, International Journal of Computer Science and Mobile Computing, Vol.4 Issue.1, January- 2015, pg. 291-306 Pass 4 : 11,22,33,44,77,88,66,55 Pass 5 : 11,22,33,44,55,77,88,66 Pass 6 : 11,22,33,44,55,66,77,88 Advantages: 1. Efficient for small list and mostly sorted list. 2. Sort big array slowly. 3. Save memory 2.3. Selection sort: A selection sort is one in which successive elements are selected in order and placed into their proper sorted positions. The elements of the input may have to be preprocessed to make the ordered selection possible. This sort is used to represent the selection of an element and keeping it in sorted order. Suppose an array A with n elements in memory. The selection sort algorithm for sorting an array A works as follows. i) To find the smallest element in the list and put in the first position. ii) To find the second smallest element in the list and put in the second position and so on. Ex; Consider the following numbers are stored in an array: Original Array : 77,33,44,11,88,22,66,55 Pass 1 :11,33,44,77,88,22,66,55 Pass 2 :11,22,44,77,88,33,66,55 Pass 3 :11,22,33,77,88,44,66,55 Pass 4 :11,22,33,44,88,77,66,55 Pass 5 :11,22,33,44,55,77,66,88 Pass 6 :11,22,33,44,55,66,77,88 Advantages: 1. Improves the performance of bubble sort and also slow. 2. Unstable but can be implemented as a stable sort. 3. Quite slow for large amount of data. © 2015, IJCSMC All Rights Reserved 294 V.P.Kulalvaimozhi et al, International Journal of Computer Science and Mobile Computing, Vol.4 Issue.1, January- 2015, pg. 291-306 2.4. Shell sort: Shell sort is also called Diminishing increment sort. D.L. Shell proposed an improvement on insertion sort in 1959 named after him as shell sort. This method sorts separate sub files of the original file. These sub files contain every kth element of the original file. The value of k is called an increment.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages16 Page
-
File Size-