Skip main navigation

£199.99 £139.99 for one year of Unlimited learning. Offer ends on 28 February 2023 at 23:59 (UTC). T&Cs apply

Find out more

What is sorting, and why do we do it?

In this article, James Robinson describes a few reasons that we might want to sort objects or data.

Humans like to categorise and order things, to greater or lesser degrees.

If you walk into a kitchen, the chances are that you will find there is a drawer set aside for utensils, a cupboard shelf for cups, and another shelf for glasses. There might be a cupboard for plates and bowls, and a separate one for frying pans and saucepans.

Have a look at a bookshelf. Maybe the books are displayed randomly, but often they’ll be organised; maybe by size, by author, by subject matter, or alphabetically by title.

Think about the last time you walked into a supermarket. The fresh vegetables and fruit will have been placed together, bakery goods somewhere else in the shop, tinned goods in another aisle. Then there will be a further organisation after that, with all the apples being in the same area, but with each variety of apple occupying its own smaller space within that.

Humans tend to categorise and order things as an energy saving mechanism. When you want to find a teaspoon you don’t have to open every drawer and cupboard in the kitchen to find it. You know which drawer you keep them in. Furthermore, once you open the drawer, you probably don’t have to keep picking out random items of cutlery until you find a teaspoon, as they’ll be organised into their own little compartment within the drawer. By spending some time and energy categorising and sorting the kitchenware, you save yourself time and energy each time you need to locate a specific object.

Humans also sort information, as well as physical objects. Think about any list of names: they will almost always be presented alphabetically to make individual easier to find. When you are going on holiday and want to choose a hotel, you might want to sort the options in lots of different ways, such as price, proximity to the beach, or the ratings of other customers.

As sorting is so important to us, it is no surprise that we have developed algorithms to assist us in sorting data, and there are plenty of them to choose from. Wikipedia alone list 34 different sorting algorithms.

But before we think about how we might develop a sorting algorithm, think about how you would go about instructing another person to sort a deck of playing cards. Imagine you have to write down instructions for sorting the deck. What would be your first instruction? Where would there be repetition of the same instruction? How would the person know that their deck is sorted?

Share your thoughts and ideas in the comments section below.

This article is from the free online

Programming 102: Think Like a Computer Scientist

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education