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; 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 \left( n \right). For typical sorting algorithms good behavior is  \mathcal{O}\left( n \log n\right) and bad behavior is \mathcal{O}\left( n^2 \right). (See Big O notation) Ideal behavior for a sort is \mathcal{O}\left( n \right). Comparison sorts, sort algorithms which only access the list via an abstract key comparison operation, need at least \mathcal{O}\left( n \log n\right)comparisons for most inputs.
  • Computational complexity of swaps (for "in place" algorithms).
  • Memory usage (and use of other computer resources). In particular, some sorting algorithms are "in place". This means that they need only  \mathcal{O}(1) or \mathcal{O}(\log n) memory beyond the items being sorted and they don't need to create auxiliary locations for data to be temporarily stored, as in other sorting algorithms.
  • Recursion. Some algorithms are either recursive or non-recursive, while others may be both (e.g., merge sort).
  • Stability: stable sorting algorithms maintain the relative order of records with equal keys (i.e., values).
  • Whether or not they are a comparison sort. A comparison sort examines the data only by comparing two elements with a comparison operator.
  • General method: insertion, exchange, selection, merging, etc. Exchange sorts include bubble sort and quicksort. Selection sorts include shaker sort and heapsort.
  • Adaptability: Whether or not the presortedness of the input affects the running time. Algorithms that take this into account are known to be adaptive.

FOR EXAMPLE, 
SEE THE JAVA APPLET FOR THE SORTING ALGORITHMS IN LINK BELOW:


http://maven.smith.edu/~thiebaut/java/sort/





No Comment.

Add Your Comment

Your Comment