Computers can put things in order.
Computers use special rules to sort things. 
Computers use special rules to sort lists. These rules are called sorting algorithms. 
A good sort must follow two rules. First, the items must stay in order. Second, the list must have all the original items. It just changes their places.
Some sorts are "stable." This means they keep the original order for items that are the same. Imagine sorting playing cards by their rank.
There are many ways to sort. Some use "exchange" methods. These swap items to find the right spot. Others use "selection" methods. They pick the best item and move it. Scientists still study how to make the fastest sorts for small groups of items.
Computers often need to organize information into a specific order. This task is done using a sorting algorithm. An algorithm is just a set of rules to follow. Most often, computers sort numbers from smallest to largest. They can also sort words into alphabetical order. 
There are many different ways to sort a list. Some methods use an exchange style. This means the computer swaps items to find the right spot. Bubble sort is a famous example of this. 
People have been studying how to sort for a long time. This problem is famous because it seems simple but is actually quite hard to solve perfectly. Researchers have worked on this since the very beginning of computing. Around 1951, a person named Betty Holberton worked on early sorting. She worked on famous computers like the ENIAC and the UNIVAC. Later, in 1956, scientists analyzed the bubble sort method. Many fast ways to sort have been known since the middle of the 20th century. New ways are still being invented today. For example, Timsort was made in 2002, and library sort was published in 2006.
Scientists use math to see how well a sort works. They look at the best, worst, and average cases. This helps them understand how much time or memory a sort uses. A common way to measure this is using something called big O notation.
Sorting algorithms are a big part of learning about computers. They are often the first thing students learn in science classes. These algorithms help students understand how computers think and solve problems. They introduce ideas like how to divide a big job into smaller parts. This is called a divide-and-conquer approach. 
In computer science, a sorting algorithm is a specific set of rules used to organize elements of a list. Most commonly, these algorithms arrange data in numerical or lexicographical order. Lexicographical order refers to the way words are organized alphabetically. Sorting can be done in ascending order, from smallest to largest, or descending order, from largest to smallest. Efficient sorting is vital because it optimizes other processes. For instance, search and merge algorithms run much faster when their input data is already sorted. Sorting also helps in canonicalizing data, which means putting it into a standard, consistent format.
To be considered successful, a sorting algorithm must satisfy two strict mathematical conditions. First, the output must be in monotonic order. This means every element is either greater than or equal to the previous one, or less than or equal to it. Second, the output must be a permutation of the input. A permutation is a reordering that retains every single original element without adding or losing any. While some algorithms are designed for sequential access, the most powerful ones assume the data is in a structure that allows random access. Random access means the computer can jump directly to any specific item in the list.

Algorithms are often classified by how they move data. Comparison sorts are a major category where the computer examines data only by comparing two elements at a time. These algorithms have a fundamental mathematical limit. They require a minimum of n log n - 1.4427n + O(log n) comparisons to work. However, non-comparison sorts, such as counting sort, can sometimes perform even better. Sorting can also be categorized by its method of movement. Exchange sorts, like bubble sort or quicksort, work by swapping items. Selection sorts, including heapsort, work by picking specific items to move. Other methods include insertion, merging, and even specialized types like the library sort.
Another important concept is stability. A stable sorting algorithm maintains the relative order of records that have equal keys. A key is the specific part of the data used for the sort. For example, if you sort playing cards by rank, the two 5s in a deck have equal keys. A stable sort ensures that if one 5 was originally above the other, it stays above it in the final list.
Researchers have studied sorting since the very beginning of computing. The problem is famous because it is easy to describe but difficult to solve perfectly. In 1951, Betty Holberton worked on early sorting for the ENIAC and UNIVAC computers. By 1956, scientists were already analyzing the bubble sort method. While many optimal algorithms were discovered in the mid-20th century, new ones are still being created. Timsort was introduced in 2002, and the library sort was published in 2006. Even today, finding the best way to sort very small arrays of fewer than 20 elements remains an open research problem.
Computer scientists use Big O notation to measure the complexity of these algorithms. Complexity describes how the running time or memory usage changes as the list grows larger. For typical serial algorithms, good behavior is O(n log n), while bad behavior can reach O(n^2). Some algorithms are also described as "in-place." A strictly in-place sort requires only O(1) additional memory beyond the items being sorted. Others are called "adaptive," meaning they run faster if the input list is already partially sorted. Some are "online," meaning they can process a constant stream of data as it arrives.
Sorting is a fundamental topic in introductory computer science classes. It provides a gateway to many core concepts, such as divide-and-conquer strategies and various data structures. Students learn about heaps, binary trees, and randomized algorithms through sorting. It also introduces the idea of time-space tradeoffs, where a programmer must choose between using more memory or more time. As computing moves toward parallel machines, finding the most optimal ways to sort across many processors remains a major area of study for scientists around the world.
🖼️ Images & Media (5)
More to explore
✨ What else?
Related topics you might enjoy
🔬 Go deeper
More advanced topics to explore
🪜 Step back
Simpler topics to build understanding
What is Nepedia?
A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.