An Enhancement of Major Sorting Algorithms

Total Page:16

File Type:pdf, Size:1020Kb

An Enhancement of Major Sorting Algorithms The International Arab Journal of Information Technology, Vol. 7, No. 1, January 2010 55 An Enhancement of Major Sorting Algorithms Jehad Alnihoud and Rami Mansi Department of Computer Science, Al al-Bayt University, Jordan Abstract: One of the fundamental issues in computer science is ordering a list of items. Although there is a huge number of sorting algorithms, sorting problem has attracted a great deal of research; because efficient sorting is important to optimize the use of other algorithms. This paper presents two new sorting algorithms, enhanced selection sort and enhanced bubble Sort algorithms. Enhanced selection sort is an enhancement on selection sort by making it slightly faster and stable sorting algorithm. Enhanced bubble sort is an enhancement on both bubble sort and selection sort algorithms with O(nlgn) complexity instead of O(n 2) for bubble sort and selection sort algorithms. The two new algorithms are analyzed, implemented, tested, and compared and the results were promising . Keywords: Enhanced selection sort, enhanced bubble sort, selection sort, bubble sort, number of swaps, time complexity . Received May 27, 2008; accepted September 1, 2008 1. Introduction the complexity of solving it efficiently. Bubble sort was analyzed as early as 1956 [2]. Information growth rapidly in our world and to search Many researchers considered sorting as a solved for this information, it should be ordered in some problem. Even so, useful new sorting algorithms are sensible order. Many years ago, it was estimated that still being invented, for example, library sort was first more than half the time on many commercial computers published in 2004. Sorting algorithms are prevalent in was spent in sorting. Fortunately this is no longer true, introductory computer science classes, where the since sophisticated methods have been devised for abundance of algorithms for the problem provides a organizing data, methods which do not require that the gentle introduction to a variety of core algorithm data be kept in any special order [9]. concepts [1, 19]. In [1], they classified sorting Many algorithms are very well known for sorting the algorithms by: unordered lists. Most important of them are Heap sort, Bubble sort, Insertion sort and shell sort [17]. As stated • Computational complexity (worst, average and best in [5], sorting has been considered as a fundamental behavior) of element comparisons in terms of list problem in the study of algorithms, that due to many size ( n). For typical sorting algorithms good reasons: behavior is O(n log n) and bad behavior is Ω( n²). Ideal behavior for a sort is O( n). Sort algorithms • The need to sort information is inherent in many which only use an abstract key comparison applications. operation always need Ω( n log n) comparisons in • Algorithms often use sorting as a key subroutine. the worst case. • In algorithm design there are many essential • Number of swaps (for in-place algorithms). techniques represented in the body of sorting • Stability: stable sorting algorithms maintain the algorithms. relative order of records with equal keys (values). • Many engineering issues come to the fore when That is, a sorting algorithm is stable if whenever implementing sorting algorithms. there are two records R and S with the same key Efficient sorting is important to optimize the use of and with R appearing before S in the original list, R other algorithms that require sorted lists to work will appear before S in the sorted list. correctly; it is also often in producing human-readable • Usage of memory and other computer resources. output. Formally, the output should satisfy two major Some sorting algorithms are “in place”, such that conditions: only O(1) or O(log n) memory is needed beyond the items being sorted, while others need to create • The output is in non-decreasing order. auxiliary locations for data to be temporarily stored. • The output is a permutation, or reordering, of the • Recursion: some algorithms are either recursive or input. non recursive, while others may be both (e.g., Since the early beginning of computing, the sorting merge sort). problem has attracted many researchers, perhaps due to • Whether or not they are a comparison sort. A comparison sort examines the data only by 56 The International Arab Journal of Information Technology, Vol. 7, No. 1, January 2010 comparing two elements with a comparison operator. 4 max := array(index) 5 for a:= 0 to size-2 do In this paper, two new sorting algorithms are 6 if array(a) ≥ max then presented. These new algorithms may consider as 7 max := array(a) selection sort as well as bubble sort algorithms. The 8 index := a study shows that the proposed algorithms are more 9 end if efficient, theoretically, analytically, and practically as 10 end for compared to the original sorting algorithms. Section 2 11 if index ≠ size-1 then presents the concept of enhanced Selection Sort (SS) 12 temp := array(size-1) algorithm and its pseudocode. Furthermore, the 13 array(size-1) := max 14 array(index) := temp implementation, analysis, and comparison with 15 end if selection sort are highlighted. Section 3 introduces 16 size := size-1 enhanced bubble sort algorithm and its pseudocode, 17 return Enhanced Selection Sort (array , size) implementation, analysis, and comparison with bubble 18 else sort. Also, a real-world case study for the proposed 19 return array algorithms is presented in section 4. Finally, 20 end if conclusions were presented in section 5. 2.4. Analysis 2. Enhanced Selection Sort For loop, in line 5 iterates n times in the first call then 2.1. Concept n keeps decreasing by one. We may say that: 0 n = 0 T ( n ) = (1) Inserting an array of elements and sorting these n + T ( n − )1 n > 0 elements in the same array (in-place) by finding the maximum element and exchanging it with the last T(n) = n + T(n-1) element, and then decreasing the size of the array by = n + n-1 + T(n-2) one for next call. In fact, the Enhanced Selection Sort = n + n-1 + n-2 + T(n-3) (2) (ESS) algorithm is an enhancement to the SS algorithm = n + n-1 + n-2 + n-3 + T(n-4) in decreasing number of swap operations, making the = … = n + n-1 + n-2 + n-3 + … + algorithm to be data dependent, and in making it stable. (n- k+1) + T(n-k) The differences between ESS and SS algorithms are discussed in section 2.5. n = ∑ i + T ( n − , fkor) n ≥ k i=n−k +1 2.2. Procedures To terminate the recursion, we should have n - k = 0 The procedures of the algorithms can be described as => k = n: follows: n n n+1 • Inserting all elements of the array. ∑ i + T )0( = ∑ i + 0 = n (3) i=1 i=1 2 • Calling the “Enhanced Selection Sort” function with n + 1 T ( n ) = n = O ( n 2 ) passing the array and its size as parameters. So, 2 (4) • Finding the maximum element in the array and swapping it with the last index of the same array. ESS algorithm is easy to analyze compared to other • Decreasing the size of the array by one. sorting algorithms since the loop does not depend on • Calling the “Enhanced Selection Sort” function the data in the array. Selecting the highest element recursively. The size of the array is decremented by requires scanning all n elements (this takes n - 1 one after each call of the “Enhanced Selection Sort” comparisons) and then swapping it into the last function. Operationally, the ( size ) after the first call position. Then, finding the next highest element became ( size-1), and after the second call became requires scanning the remaining n - 2 elements and so (size-2), and so on. on, for ( n-1)+( n-2)+...+2+1 = n(n-1)/2 = O( n2) comparisons. 2.3. Pseudocode The number of swaps in the proposed algorithm may elaborate as follows: In simple pseudocode, enhanced selection sort algorithm might be expressed as: a) In the best-case scenario; if the input array is already sorted (ascending order), then there is no function enhanced selection sort (array , size) need to make swapping, since each element is in 1 if size > 1 then the correct place. 2 var index, temp, max b) In the average-case scenario; if the input array is 3 index := size-1 sorted in reverse (descending order), then the An Enhancement of Major Sorting Algorithms 57 total number of swapping operations is: floor of perform any swap operation, but selection sort (n/2). Since swapping the maximum value with the performs n swap operations. Writing in memory is last element means that the maximum and the more expensive in time than reading, since EBS minimum values are in the correct places. For performs less number of swaps (read/write) then it is example, if we have a descending sorted array as more efficient than selection sort when dealing with follows: an array stored in a secondary memory or in EEPROM (electrically erasable programmable read only 5 4 3 2 1 memory). However, there are many similarities Then the algorithm will swap the first element (max) between ESS and SS algorithms, as shown in Table 1. with the last element, as follows: Table 1. ESS vs SS algorithms. 1 4 3 2 5 Enhanced Selection Criteria Selection Sort Sort Since the last element before swapping was the Best Case O( n2) O( n2) minimum value, it is after swapping got in the correct Average Case O( n2) O( n2) 2 2 place and cannot be the maximum value in any of the Worst Case O( n ) O( n ) Memory O(1) O(1) next comparisons.
Recommended publications
  • Coursenotes 4 Non-Adaptive Sorting Batcher's Algorithm
    4. Non Adaptive Sorting Batcher’s Algorithm 4.1 Introduction to Batcher’s Algorithm Sorting has many important applications in daily life and in particular, computer science. Within computer science several sorting algorithms exist such as the “bubble sort,” “shell sort,” “comb sort,” “heap sort,” “bucket sort,” “merge sort,” etc. We have actually encountered these before in section 2 of the course notes. Many different sorting algorithms exist and are implemented differently in each programming language. These sorting algorithms are relevant because they are used in every single computer program you run ranging from the unimportant computer solitaire you play to the online checking account you own. Indeed without sorting algorithms, many of the services we enjoy today would simply not be available. Batcher’s algorithm is a way to sort individual disorganized elements called “keys” into some desired order using a set number of comparisons. The keys that will be sorted for our purposes will be numbers and the order that we will want them to be in will be from greatest to least or vice a versa (whichever way you want it). The Batcher algorithm is non-adaptive in that it takes a fixed set of comparisons in order to sort the unsorted keys. In other words, there is no change made in the process during the sorting. Unlike other methods of sorting where you need to remember comparisons (tournament sort), Batcher’s algorithm is useful because it requires less thinking. Non-adaptive sorting is easy because outcomes of comparisons made at one point of the process do not affect which comparisons will be made in the future.
    [Show full text]
  • An Evolutionary Approach for Sorting Algorithms
    ORIENTAL JOURNAL OF ISSN: 0974-6471 COMPUTER SCIENCE & TECHNOLOGY December 2014, An International Open Free Access, Peer Reviewed Research Journal Vol. 7, No. (3): Published By: Oriental Scientific Publishing Co., India. Pgs. 369-376 www.computerscijournal.org Root to Fruit (2): An Evolutionary Approach for Sorting Algorithms PRAMOD KADAM AND Sachin KADAM BVDU, IMED, Pune, India. (Received: November 10, 2014; Accepted: December 20, 2014) ABstract This paper continues the earlier thought of evolutionary study of sorting problem and sorting algorithms (Root to Fruit (1): An Evolutionary Study of Sorting Problem) [1]and concluded with the chronological list of early pioneers of sorting problem or algorithms. Latter in the study graphical method has been used to present an evolution of sorting problem and sorting algorithm on the time line. Key words: Evolutionary study of sorting, History of sorting Early Sorting algorithms, list of inventors for sorting. IntroDUCTION name and their contribution may skipped from the study. Therefore readers have all the rights to In spite of plentiful literature and research extent this study with the valid proofs. Ultimately in sorting algorithmic domain there is mess our objective behind this research is very much found in documentation as far as credential clear, that to provide strength to the evolutionary concern2. Perhaps this problem found due to lack study of sorting algorithms and shift towards a good of coordination and unavailability of common knowledge base to preserve work of our forebear platform or knowledge base in the same domain. for upcoming generation. Otherwise coming Evolutionary study of sorting algorithm or sorting generation could receive hardly information about problem is foundation of futuristic knowledge sorting problems and syllabi may restrict with some base for sorting problem domain1.
    [Show full text]
  • Bubble Sort: an Archaeological Algorithmic Analysis
    Bubble Sort: An Archaeological Algorithmic Analysis Owen Astrachan 1 Computer Science Department Duke University [email protected] Abstract 1 Introduction Text books, including books for general audiences, in- What do students remember from their first program- variably mention bubble sort in discussions of elemen- ming courses after one, five, and ten years? Most stu- tary sorting algorithms. We trace the history of bub- dents will take only a few memories of what they have ble sort, its popularity, and its endurance in the face studied. As teachers of these students we should ensure of pedagogical assertions that code and algorithmic ex- that what they remember will serve them well. More amples used in early courses should be of high quality specifically, if students take only a few memories about and adhere to established best practices. This paper is sorting from a first course what do we want these mem- more an historical analysis than a philosophical trea- ories to be? Should the phrase Bubble Sort be the first tise for the exclusion of bubble sort from books and that springs to mind at the end of a course or several courses. However, sentiments for exclusion are sup- years later? There are compelling reasons for excluding 1 ported by Knuth [17], “In short, the bubble sort seems discussion of bubble sort , but many texts continue to to have nothing to recommend it, except a catchy name include discussion of the algorithm after years of warn- and the fact that it leads to some interesting theoreti- ings from scientists and educators.
    [Show full text]
  • Data Structures & Algorithms
    DATA STRUCTURES & ALGORITHMS Tutorial 6 Questions SORTING ALGORITHMS Required Questions Question 1. Many operations can be performed faster on sorted than on unsorted data. For which of the following operations is this the case? a. checking whether one word is an anagram of another word, e.g., plum and lump b. findin the minimum value. c. computing an average of values d. finding the middle value (the median) e. finding the value that appears most frequently in the data Question 2. In which case, the following sorting algorithm is fastest/slowest and what is the complexity in that case? Explain. a. insertion sort b. selection sort c. bubble sort d. quick sort Question 3. Consider the sequence of integers S = {5, 8, 2, 4, 3, 6, 1, 7} For each of the following sorting algorithms, indicate the sequence S after executing each step of the algorithm as it sorts this sequence: a. insertion sort b. selection sort c. heap sort d. bubble sort e. merge sort Question 4. Consider the sequence of integers 1 T = {1, 9, 2, 6, 4, 8, 0, 7} Indicate the sequence T after executing each step of the Cocktail sort algorithm (see Appendix) as it sorts this sequence. Advanced Questions Question 5. A variant of the bubble sorting algorithm is the so-called odd-even transposition sort . Like bubble sort, this algorithm a total of n-1 passes through the array. Each pass consists of two phases: The first phase compares array[i] with array[i+1] and swaps them if necessary for all the odd values of of i.
    [Show full text]
  • 13 Basic Sorting Algorithms
    Concise Notes on Data Structures and Algorithms Basic Sorting Algorithms 13 Basic Sorting Algorithms 13.1 Introduction Sorting is one of the most fundamental and important data processing tasks. Sorting algorithm: An algorithm that rearranges records in lists so that they follow some well-defined ordering relation on values of keys in each record. An internal sorting algorithm works on lists in main memory, while an external sorting algorithm works on lists stored in files. Some sorting algorithms work much better as internal sorts than external sorts, but some work well in both contexts. A sorting algorithm is stable if it preserves the original order of records with equal keys. Many sorting algorithms have been invented; in this chapter we will consider the simplest sorting algorithms. In our discussion in this chapter, all measures of input size are the length of the sorted lists (arrays in the sample code), and the basic operation counted is comparison of list elements (also called keys). 13.2 Bubble Sort One of the oldest sorting algorithms is bubble sort. The idea behind it is to make repeated passes through the list from beginning to end, comparing adjacent elements and swapping any that are out of order. After the first pass, the largest element will have been moved to the end of the list; after the second pass, the second largest will have been moved to the penultimate position; and so forth. The idea is that large values “bubble up” to the top of the list on each pass. A Ruby implementation of bubble sort appears in Figure 1.
    [Show full text]
  • Investigating the Effect of Implementation Languages and Large Problem Sizes on the Tractability and Efficiency of Sorting Algorithms
    International Journal of Engineering Research and Technology. ISSN 0974-3154, Volume 12, Number 2 (2019), pp. 196-203 © International Research Publication House. http://www.irphouse.com Investigating the Effect of Implementation Languages and Large Problem Sizes on the Tractability and Efficiency of Sorting Algorithms Temitayo Matthew Fagbola and Surendra Colin Thakur Department of Information Technology, Durban University of Technology, Durban 4000, South Africa. ORCID: 0000-0001-6631-1002 (Temitayo Fagbola) Abstract [1],[2]. Theoretically, effective sorting of data allows for an efficient and simple searching process to take place. This is Sorting is a data structure operation involving a re-arrangement particularly important as most merge and search algorithms of an unordered set of elements with witnessed real life strictly depend on the correctness and efficiency of sorting applications for load balancing and energy conservation in algorithms [4]. It is important to note that, the rearrangement distributed, grid and cloud computing environments. However, procedure of each sorting algorithm differs and directly impacts the rearrangement procedure often used by sorting algorithms on the execution time and complexity of such algorithm for differs and significantly impacts on their computational varying problem sizes and type emanating from real-world efficiencies and tractability for varying problem sizes. situations [5]. For instance, the operational sorting procedures Currently, which combination of sorting algorithm and of Merge Sort, Quick Sort and Heap Sort follow a divide-and- implementation language is highly tractable and efficient for conquer approach characterized by key comparison, recursion solving large sized-problems remains an open challenge. In this and binary heap’ key reordering requirements, respectively [9].
    [Show full text]
  • Fall, 2016 Lab #3
    Texas Christian University CoSc 20803 - Fall, 2016 Lab #3 Points: 100 points Language: Java Due Date: Midnight, Thursday, Nov 17, 2016 (complete Java project and manually-generated Excel spreadsheet ZIPped together and submitted with TURNIN). Purpose: The purpose of this assignment is to allow you to evaluate the performance of several different sorting algorithms on data in various degrees of disorder. Processing: You should implement the following sorting algorithms and gather statistics as noted below: Method #1 Method #2 Method #3 Method #4 Bubblesort Cocktail Shaker Sort Shell Sort Quick Sort (pp. 230-232) (discussed in class) (discussed in class) (pp. 232-236) Input: Three input data sets will be provided (each of which contains 5000, 4-byte alphanumeric keys). The files are: Ascending.dat, Descending.dat, and Random.dat (obtainable from the CoSc Department’s class website: GUI: For this lab you should develop a manual data collection program that employs a VERY SIMPLE graphical user interface. Your program should accommodate input from the user specifying: a) the integer number of records to be sorted, b) the name of the input file to be used as the source of data (via a JFileChooser()), and c) the sorting method to use. Your program should allow the sorting methods listed above to be performed. Statistics: You should sort, ascendingly, alphanumeric keys in each of the three data files provided, keeping statistics for each file and for each sort method. Keep track of: (i) the number of key compares (Ki:Kj) and (ii) the number of key moves (e.g., Ki <--- Kj).
    [Show full text]
  • Sorting Partnership Unless You Sign Up! Brian Curless • Homework #5 Will Be Ready After Class, Spring 2008 Due in a Week
    Announcements (5/9/08) • Project 3 is now assigned. CSE 326: Data Structures • Partnerships due by 3pm – We will not assume you are in a Sorting partnership unless you sign up! Brian Curless • Homework #5 will be ready after class, Spring 2008 due in a week. • Reading for this lecture: Chapter 7. 2 Sorting Consistent Ordering • Input – an array A of data records • The comparison function must provide a – a key value in each data record consistent ordering on the set of possible keys – You can compare any two keys and get back an – a comparison function which imposes a indication of a < b, a > b, or a = b (trichotomy) consistent ordering on the keys – The comparison functions must be consistent • Output • If compare(a,b) says a<b, then compare(b,a) must say b>a • If says a=b, then must say b=a – reorganize the elements of A such that compare(a,b) compare(b,a) • If compare(a,b) says a=b, then equals(a,b) and equals(b,a) • For any i and j, if i < j then A[i] ≤ A[j] must say a=b 3 4 Why Sort? Space • How much space does the sorting • Allows binary search of an N-element algorithm require in order to sort the array in O(log N) time collection of items? • Allows O(1) time access to kth largest – Is copying needed? element in the array for any k • In-place sorting algorithms: no copying or • Sorting algorithms are among the most at most O(1) additional temp space.
    [Show full text]
  • Sorting Algorithm 1 Sorting Algorithm
    Sorting algorithm 1 Sorting algorithm In computer science, 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 for optimizing the use of other algorithms (such as search and merge algorithms) that require sorted lists to work correctly; it is also often useful for canonicalizing data and for producing human-readable output. More formally, the output must satisfy two conditions: 1. The output is in nondecreasing order (each element is no smaller than the previous element according to the desired total order); 2. The output is a permutation, or reordering, of the input. Since the dawn of computing, the sorting problem has attracted a great deal of research, perhaps due to the complexity of solving it efficiently despite its simple, familiar statement. For example, bubble sort was analyzed as early as 1956.[1] Although many consider it a solved problem, useful new sorting algorithms are still being invented (for example, library sort was first published in 2004). Sorting algorithms are prevalent in introductory computer science classes, where the abundance of algorithms for the problem provides a gentle introduction to a variety of core algorithm concepts, such as big O notation, divide and conquer algorithms, data structures, randomized algorithms, best, worst and average case analysis, time-space tradeoffs, and lower bounds. Classification Sorting algorithms used in computer science are often classified by: • Computational complexity (worst, average and best behaviour) of element comparisons in terms of the size of the list . For typical sorting algorithms good behavior is and bad behavior is .
    [Show full text]
  • Visvesvaraya Technological University a Project Report
    ` VISVESVARAYA TECHNOLOGICAL UNIVERSITY “Jnana Sangama”, Belagavi – 590 018 A PROJECT REPORT ON “PREDICTIVE SCHEDULING OF SORTING ALGORITHMS” Submitted in partial fulfillment for the award of the degree of BACHELOR OF ENGINEERING IN COMPUTER SCIENCE AND ENGINEERING BY RANJIT KUMAR SHA (1NH13CS092) SANDIP SHAH (1NH13CS101) SAURABH RAI (1NH13CS104) GAURAV KUMAR (1NH13CS718) Under the guidance of Ms. Sridevi (Senior Assistant Professor, Dept. of CSE, NHCE) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING NEW HORIZON COLLEGE OF ENGINEERING (ISO-9001:2000 certified, Accredited by NAAC ‘A’, Permanently affiliated to VTU) Outer Ring Road, Panathur Post, Near Marathalli, Bangalore – 560103 ` NEW HORIZON COLLEGE OF ENGINEERING (ISO-9001:2000 certified, Accredited by NAAC ‘A’ Permanently affiliated to VTU) Outer Ring Road, Panathur Post, Near Marathalli, Bangalore-560 103 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING CERTIFICATE Certified that the project work entitled “PREDICTIVE SCHEDULING OF SORTING ALGORITHMS” carried out by RANJIT KUMAR SHA (1NH13CS092), SANDIP SHAH (1NH13CS101), SAURABH RAI (1NH13CS104) and GAURAV KUMAR (1NH13CS718) bonafide students of NEW HORIZON COLLEGE OF ENGINEERING in partial fulfillment for the award of Bachelor of Engineering in Computer Science and Engineering of the Visvesvaraya Technological University, Belagavi during the year 2016-2017. It is certified that all corrections/suggestions indicated for Internal Assessment have been incorporated in the report deposited in the department library. The project report has been approved as it satisfies the academic requirements in respect of Project work prescribed for the Degree. Name & Signature of Guide Name Signature of HOD Signature of Principal (Ms. Sridevi) (Dr. Prashanth C.S.R.) (Dr. Manjunatha) External Viva Name of Examiner Signature with date 1.
    [Show full text]
  • Evaluation of Sorting Algorithms, Mathematical and Empirical Analysis of Sorting Algorithms
    International Journal of Scientific & Engineering Research Volume 8, Issue 5, May-2017 86 ISSN 2229-5518 Evaluation of Sorting Algorithms, Mathematical and Empirical Analysis of sorting Algorithms Sapram Choudaiah P Chandu Chowdary M Kavitha ABSTRACT:Sorting is an important data structure in many real life applications. A number of sorting algorithms are in existence till date. This paper continues the earlier thought of evolutionary study of sorting problem and sorting algorithms concluded with the chronological list of early pioneers of sorting problem or algorithms. Latter in the study graphical method has been used to present an evolution of sorting problem and sorting algorithm on the time line. An extensive analysis has been done compared with the traditional mathematical methods of ―Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, Quick Sort. Observations have been obtained on comparing with the existing approaches of All Sorts. An “Empirical Analysis” consists of rigorous complexity analysis by various sorting algorithms, in which comparison and real swapping of all the variables are calculatedAll algorithms were tested on random data of various ranges from small to large. It is an attempt to compare the performance of various sorting algorithm, with the aim of comparing their speed when sorting an integer inputs.The empirical data obtained by using the program reveals that Quick sort algorithm is fastest and Bubble sort is slowest. Keywords: Bubble Sort, Insertion sort, Quick Sort, Merge Sort, Selection Sort, Heap Sort,CPU Time. Introduction In spite of plentiful literature and research in more dimension to student for thinking4. Whereas, sorting algorithmic domain there is mess found in this thinking become a mark of respect to all our documentation as far as credential concern2.
    [Show full text]
  • Sorting Algorithm 1 Sorting Algorithm
    Sorting algorithm 1 Sorting algorithm 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 for optimizing the use of other algorithms (such as search and merge algorithms) which require input data to be in sorted lists; it is also often useful for canonicalizing data and for producing human-readable output. More formally, the output must satisfy two conditions: 1. The output is in nondecreasing order (each element is no smaller than the previous element according to the desired total order); 2. The output is a permutation (reordering) of the input. Since the dawn of computing, the sorting problem has attracted a great deal of research, perhaps due to the complexity of solving it efficiently despite its simple, familiar statement. For example, bubble sort was analyzed as early as 1956.[1] Although many consider it a solved problem, useful new sorting algorithms are still being invented (for example, library sort was first published in 2006). Sorting algorithms are prevalent in introductory computer science classes, where the abundance of algorithms for the problem provides a gentle introduction to a variety of core algorithm concepts, such as big O notation, divide and conquer algorithms, data structures, randomized algorithms, best, worst and average case analysis, time-space tradeoffs, and upper and lower bounds. Classification Sorting algorithms are often classified by: • Computational complexity (worst, average and best behavior) of element comparisons in terms of the size of the list (n). For typical serial sorting algorithms good behavior is O(n log n), with parallel sort in O(log2 n), and bad behavior is O(n2).
    [Show full text]