Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Sorting
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==={{anchor|Sort/Merge}}Information or data=== In {{visible anchor|[[computer science]]}}, arranging in an ordered sequence is called "sorting". Sorting is a common operation in many applications, and efficient [[Sorting algorithm|algorithms]] have been developed to perform it. The most common uses of sorted sequences are: * making [[search algorithm|lookup or search]] efficient; * making [[merge algorithm|merging of sequences]] efficient; * enabling [[data processing|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]]. For sorting, either a weak order, "should not come after", can be specified, or a [[strict weak order]], "should come before" (specifying one defines also the other, the two are the complement of the inverse of each other, see [[Binary relation#Operations|operations on binary relations]]). For the sorting to be unique, these two are restricted to a [[total order]] and a strict total order, respectively. Sorting [[n-tuple]]s (depending on context also called e.g. [[Object composition|record]]s 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 [[collation#sort keys|sort key]] can be created from two or more sort keys by [[lexicographical order]]. 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 [[total order|totally ordered]], the sort key defines a [[strict weak ordering#Total preorders|weak order]] of the items: items with the same sort key are equivalent with respect to sorting. See also [[Sorting algorithm#Stability|stable sorting]]. If different items have different sort key values then this defines a unique order of the items. [[File:Bundesarchiv Bild 183-22350-0001, Berlin, Postamt O 17, Päckchenverteilung.jpg|thumb|Workers sorting parcels in a postal facility]] 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==== {{main|Sorting algorithm}} * '''[[Bubble sort|Bubble]]/[[Shell sort]]''': Exchange two adjacent elements if they are out of order. Repeat until array is sorted. * '''[[Insertion sort]]''': 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]]''': 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]]''': Divide the list of elements in two parts, sort the two parts individually and then merge it.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Sorting
(section)
Add topic