Auditory Algorithms

Computational Thinking, Creativity, Education, MSU MAET

“For me, great algorithms are the poetry of computation. Just like verse, they can be terse, allusive, dense, and even mysterious. But once unlocked, they cast a brilliant new light on some aspect of computing.” – Francis Sullivan

Algorithms are found throughout mathematics and computer science. Whether it’s teaching students how to multiply multi-digit numbers or using a sorting routine to place information in order, following step-by-step instructions to achieve a consistent result is quite useful in those disciplines.

In our daily lives we also encounter many algorithms:

My favorite recipe for chocolate chip cookies

Instructions for using shampoo, such as: To use: Apply shampoo to wet hair. Massage to lather, then rinse. Repeat. Many have pointed out is an infinite loop until “Repeat” was appended with “as necessary”. It’s interesting to examine how these instructions differ based on brand or targeted gender.

XKCD comic on flowcharts

The morning routine found in A Day in the Life by The Beatles could be thought of as an algorithm, similar to one that many of us follow on a work-day morning.

Taking inspiration from my course on Computational Thinking, I reexamined a classic problem from computer science known as the Pancake Sort. The task is to sort a set of information in some way, such as from smallest to largest, but you are limited in what actions you can take.  This page on the Pancake Sort provides a good overview of how to compare it to flipping pancakes in a stack.

Algorithms are usually described visually to determine the steps being followed, as the examples above show. I chose to re-imagine a Pancake Sort by using notes on a scale to represent the information to be sorted through a program called Sonic Pi. Now not only would I be using an algorithm to create the sounds, but listening to the resulting tunes would provide a different way to perceive what an algorithm is doing as it sorts.

Three different tunes can be heard below, providing an auditory representation of the result of three different variations of a pancake sorting algorithm. The starting sequence of notes is a random ordering: 7,3,8,5,4,1,6,2. The difference between 1 and 8 is an octave, and the goal is always to get the notes in the 1,2,3,4,5,6,7,8 order.  In each tune, a sequence of the same eight notes is played repeatedly, but the order of the notes will differ each time until they are in order. The tune of a sequence can only be changed by reversing the note order as if you were flipping pancakes, with the start of each sequence acting like the top of the pancake stack. At times you might only hear a few notes at the beginning of a sequence being reversed in order through a flip. Other times the entire sequence might be reversed, as if the entire stack of pancakes was being flipped.

The first tune is the result of following a bottom-up algorithm. The lowest note is flipped to the beginning of the sequence, then flipped again to the correct position so that it does not have to be moved again. The process is repeated with the second-lowest note, etc., until the sequence is in order. Can you hear the sequence starting to take shape as the tune progresses?

[symple_toggle title=”Click to see sequence of notes” state=”closed”]



The other two tunes provide a variation on that theme.  They both start with the same 7,3,8,5,4,1,6,2 sequence, and both only perform flips to bring the notes in order, but they follow different paths to get to the ordered state.

The second tune is a simple variation – can you tell how it differs from the first tune and how the algorithm was behaving differently?

[symple_toggle title=”Click to see sequence of notes” state=”closed”]

[1,2,3,4,5,6,7,8] [/symple_toggle]


The third tune is the toughest. Can you tell what strategy it was following to get the notes in order?

[symple_toggle title=”Click to see sequence of notes” state=”closed”]



Which tune/algorithm accomplishes its task the fastest? Can we assign any aesthetic value to any of the tunes? Does any tune sound more discordant as sorting occurs than others?

Leave a Reply

Your email address will not be published. Required fields are marked *