Sorting Problem
   HOME

TheInfoList



OR:

Sorting refers to ordering data in an increasing or decreasing manner according to some linear relationship among the data items. # ordering: arranging items in a sequence ordered by some criterion; #
categorizing Classification is the activity of assigning objects to some pre-existing classes or categories. This is distinct from the task of establishing the classes themselves (for example through cluster analysis). Examples include diagnostic tests, identif ...
: grouping items with similar properties. Ordering items is the combination of categorizing them based on equivalent order, and ordering the categories themselves.


By type


Information or data

In , arranging in an ordered sequence is called "sorting". Sorting is a common operation in many applications, and efficient
algorithms In mathematics and computer science, an algorithm () is a finite sequence of mathematically rigorous instructions, typically used to solve a class of specific problems or to perform a computation. Algorithms are used as specifications for per ...
have been developed to perform it. The most common uses of sorted sequences are: * making lookup or search efficient; * making merging of sequences efficient; * enabling processing of data in a defined order. The opposite of sorting, rearranging a sequence of items in a random or meaningless order, is called
shuffling Shuffling is a technique used to randomize a deck of playing cards, introducing an element of chance into card games. Various shuffling methods exist, each with its own characteristics and potential for manipulation. One of the simplest shuf ...
. For sorting, either a weak order, "should not come after", can be specified, or a
strict weak order In mathematics, especially order theory, a weak ordering is a mathematical formalization of the intuitive notion of a ranking of a set, some of whose members may be tied with each other. Weak orders are a generalization of totally ordered set ...
, "should come before" (specifying one defines also the other, the two are the complement of the inverse of each other, see operations on binary relations). For the sorting to be unique, these two are restricted to a
total order In mathematics, a total order or linear order is a partial order in which any two elements are comparable. That is, a total order is a binary relation \leq on some set X, which satisfies the following for all a, b and c in X: # a \leq a ( re ...
and a strict total order, respectively. Sorting
n-tuple In mathematics, a tuple is a finite sequence or ''ordered list'' of numbers or, more generally, mathematical objects, which are called the ''elements'' of the tuple. An -tuple is a tuple of elements, where is a non-negative integer. There is on ...
s (depending on context also called e.g. records consisting of fields) can be done based on one or more of its components. More generally objects can be sorted based on a property. Such a component or property is called a sort key. For example, the items are books, the sort key is the title, subject or author, and the order is alphabetical. A new sort key can be created from two or more sort keys by
lexicographical order In mathematics, the lexicographic or lexicographical order (also known as lexical order, or dictionary order) is a generalization of the alphabetical order of the dictionaries to sequences of ordered symbols or, more generally, of elements of a ...
. The first is then called the primary sort key, the second the secondary sort key, etc. For example, addresses could be sorted using the city as primary sort key, and the street as secondary sort key. If the sort key values are
totally ordered In mathematics, a total order or linear order is a partial order in which any two elements are comparable. That is, a total order is a binary relation \leq on some set X, which satisfies the following for all a, b and c in X: # a \leq a ( r ...
, the sort key defines a weak order of the items: items with the same sort key are equivalent with respect to sorting. See also stable sorting. If different items have different sort key values then this defines a unique order of the items. A standard order is often called ''ascending'' (corresponding to the fact that the standard order of numbers is ascending, i.e. A to Z, 0 to 9), the reverse order ''descending'' (Z to A, 9 to 0). For dates and times, ''ascending'' means that earlier values precede later ones e.g. 1/1/2000 will sort ahead of 1/1/2001.


Common algorithms

*
Bubble Bubble, Bubbles or The Bubble may refer to: Common uses * Bubble (physics), a globule of one substance in another, usually gas in a liquid ** Soap bubble * Economic bubble, a situation where asset prices are much higher than underlying fundame ...
/ Shell sort: Exchange two adjacent elements if they are out of order. Repeat until array is sorted. *
Insertion sort Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time by comparisons. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort. Howev ...
: Scan successive elements for an out-of-order item, then insert the item in the proper place. * Selection sort: Find the smallest (or biggest) element in the array, and put it in the proper place. Swap it with the value in the first position. Repeat until array is sorted. *
Quick sort Quicksort is an efficient, general-purpose sorting algorithm. Quicksort was developed by British computer scientist Tony Hoare in 1959 and published in 1961. It is still a commonly used algorithm for sorting. Overall, it is slightly faster than ...
: Partition the array into two segments. In the first segment, all elements are less than or equal to the pivot value. In the second segment, all elements are greater than or equal to the pivot value. Finally, sort the two segments recursively. *
Merge sort In computer science, merge sort (also commonly spelled as mergesort and as ) is an efficient, general-purpose, and comparison sort, comparison-based sorting algorithm. Most implementations of merge sort are Sorting algorithm#Stability, stable, wh ...
: Divide the list of elements in two parts, sort the two parts individually and then merge it.


Physical

Various sorting tasks are essential in industrial processes, such as
mineral processing Mineral processing is the process of separating commercially valuable minerals from their ores in the field of extractive metallurgy. Depending on the processes used in each instance, it is often referred to as ore dressing or ore milling. Be ...
. For example, during the extraction of
gold Gold is a chemical element; it has chemical symbol Au (from Latin ) and atomic number 79. In its pure form, it is a brightness, bright, slightly orange-yellow, dense, soft, malleable, and ductile metal. Chemically, gold is a transition metal ...
from ore, a device called a shaker table uses
gravity In physics, gravity (), also known as gravitation or a gravitational interaction, is a fundamental interaction, a mutual attraction between all massive particles. On Earth, gravity takes a slightly different meaning: the observed force b ...
,
vibration Vibration () is a mechanical phenomenon whereby oscillations occur about an equilibrium point. Vibration may be deterministic if the oscillations can be characterised precisely (e.g. the periodic motion of a pendulum), or random if the os ...
, and flow to separate gold from lighter materials in the ore (sorting by size and weight). Sorting is also a naturally occurring process that results in the concentration of
ore Ore is natural rock or sediment that contains one or more valuable minerals, typically including metals, concentrated above background levels, and that is economically viable to mine and process. The grade of ore refers to the concentration ...
or
sediment Sediment is a solid material that is transported to a new location where it is deposited. It occurs naturally and, through the processes of weathering and erosion, is broken down and subsequently sediment transport, transported by the action of ...
. Sorting results from the application of some criterion or differential stressors to a mass to separate it into its components based on some variable quality. Materials that are different, but only slightly so, such as the isotopes of uranium, are very difficult to separate.
Optical sorting Optical sorting (sometimes called digital sorting) is the automated process of sorting solid products using cameras and/or lasers. Depending on the types of sensors used and the software-driven intelligence of the image processing system, optical ...
is an automated process of sorting solid products using cameras and/or lasers and has widespread use in the food industry. Sensor-based sorting is used in mineral processing.


See also

* Help:Sorting in Wikipedia tables. For sorting of categories, see Wikipedia:Categorization#Sort keys and for sorting of article sections, see WP:ORDER *
Collation Collation is the assembly of written information into a standard order. Many systems of collation are based on numerical order or alphabetical order, or extensions and combinations thereof. Collation is a fundamental element of most office fi ...
*
Data processing Data processing is the collection and manipulation of digital data to produce meaningful information. Data processing is a form of ''information processing'', which is the modification (processing) of information in any manner detectable by an o ...
* IBM mainframe sort/merge *
Unicode collation algorithm __NOTOC__ The Unicode collation algorithm (UCA) is an algorithm defined in Unicode Technical Report #10, which is a customizable method to produce binary keys from strings representing text in any writing system and language that can be represente ...
* Knolling *
5S (methodology) 5S (Five S) is a workplace organization method that uses a list of five Japanese words: , , , , and . These have been translated as 'sort', 'set in order', 'shine', 'standardize', and 'sustain'. The list describes how to organize a work space f ...


References


External links


Demonstration of Sorting Algorithms
(includes bubble and quicksort)
Animated video
explaining bubble sort and quick sort and compares their performance. {{commons category Sorting algorithms Data processing