Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Sorting algorithm
(section)
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!
==== Exchange sort ==== ''Exchange sort'' is sometimes confused with bubble sort, although the algorithms are in fact distinct.<ref>{{Cite web|url=https://www.codingunit.com/exchange-sort-algorithm|title=Exchange Sort Algorithm|website=CodingUnit Programming Tutorials|access-date=2021-07-10|archive-date=2021-07-10|archive-url=https://web.archive.org/web/20210710111758/https://www.codingunit.com/exchange-sort-algorithm|url-status=live}}</ref><ref>{{Cite web|url=https://mathbits.com/MathBits/Java/arrays/Exchange.htm|title=Exchange Sort|website=JavaBitsNotebook.com|access-date=2021-07-10|archive-date=2021-07-10|archive-url=https://web.archive.org/web/20210710111757/https://mathbits.com/MathBits/Java/arrays/Exchange.htm|url-status=live}}</ref> Exchange sort works by comparing the first element with all elements above it, swapping where needed, thereby guaranteeing that the first element is correct for the final sort order; it then proceeds to do the same for the second element, and so on. It lacks the advantage that bubble sort has of detecting in one pass if the list is already sorted, but it can be faster than bubble sort by a constant factor (one less pass over the data to be sorted; half as many total comparisons) in worst-case situations. Like any simple O(''n''<sup>2</sup>) sort it can be reasonably fast over very small data sets, though in general [[insertion sort]] will be faster.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)