Skip to main content

Section 8.4 Sorting

Another common operation computers need to do with data is to sort. What are the top 10 results on a web search for the term “sort algorithm”?, Rank the states of the US based on population, Print an alphabetical class roster - these are all examples of tasks that require putting data in some kind of order. Or, perhaps we want to use an algorithm like binary search that will only work on ordered data.
Much like how we can use multiple different strategies for searching, there are many possible algorithms we can use to sort a list of data. Each algorithm uses a different strategy to rearrange the data - these different strategies mean the algorithms behave differently. Some algorithms will be faster than others, maybe all the time, maybe just in certain situations. Some algorithms will produce useful results if we stop them early - like finding the smallest 5 things without completely sorting the list.
In the next few sections will learn a few sort algorithms so we can compare various strategies.
You have attempted of activities on this page.