beanz Magazine

On Sorting

Dennis Jarvis on Flickr

Have you ever put books in alphabetical order? What do you think the best method of alphabetizing would be?

Would you leave the books on the shelf and just move them one a time? Would you first put them in stacks of A’s, B’s, etc. and then sort the stacks? Maybe you’d start by picking a book and first dividing the shelf into all the books that would come before it and all the books that would come after it.

Alphabetizing is an example of a type of sorting. Sorting is when you take a number of things and put them in order. You could be sorting by date and time, by name, by author name, by size, or any notion of ordering that says “this should come before that”.

Sorting is a deeply explored topic in computer science. Computer scientists care about sorting for the same reason a bookstore cares about alphabetizing its shelves: it makes finding things much easier.

One of the simplest and most intuitive ways of sorting is called the bubble sort. You may have discovered this just by trying to put things in order!

It works like this: start from the left hand side of the list of items, until you reach the end for each element, compare it to the element to its right. If the element on the left is bigger, swap them. If the element to the right is bigger, leave them alone. Repeat with all the elements until the list is in order.

Here is a bubble sort shown as a Python algorithm that sorts a list of numbers:


Become a subscriber and get access to the rest of this article. Plus all our magazine articles.

Stories also include numerous links to help parents, kids, and teachers learn more. Get access today at just $15 per year!

Subscribe Today!

Also In The August 2017 Issue

A substitution cipher is an easy way to begin learning about how to use and make secret codes.

Scratch is a fun block-based programming language that's easy to learn once you understand the basics.

The micro:bit is a not too expensive board that lets you easily build projects to learn about computing.

The humble sewing machine can be a great first step to fun maker projects. Here's how to get started!

There's lots you can do make your online experiences enjoyable AND safe.

Minecraft is a fun game to play and a way to learn about games and programming. But first you have to learn the basics.

Have you ever put books in alphabetical order? What do you think the best method of alphabetizing would be?

Some ideas how to engage young women in computing and STEAM based on recent research.

These three dimensional objects are 3D printed and cast images when light shines through them.

How do computers predict what text you want to write next? Here's how to create predictive stories.

Links from the bottom of all the August 2017 articles, collected in one place for you to print, share, or bookmark.

Interesting stories about computer science, software programming, and technology for February 2017.