Algorithms in Colour…Fun for the Whole Family!

George Marklow
3 min readDec 8, 2020

--

The QuickSort algorithm in colour

Introduction

I came up with this idea about how we can get more kids aware of and excited about computer algorithms (and it might keep them occupied for 5 mins this holiday season).

So I ordered a couple of things from Amazon and off I went…

Things you will need

You will need the following items (links provided):

Step 1 — Choose an algorithm

You will need to find an algorithm and a worked example

For this demonstration, I will use a QuickSort algorithm, following this example:

QuickSort Algorithm (in its “boring form”)

Step 2 — Decide on the colour order

For this tutorial, we’re going to be translating numbers into colours. Therefore, we should define the natural order of our colours:

  • red
  • orange
  • yellow
  • light green
  • dark green
  • light blue
  • dark blue
  • purple
  • pink
Count and order the colours you need

Step 3— Position numbers on a card with a pencil

Following your chosen example algorithm, write all the numbers in pencil on the card first, using a ruler to get them spaced equally apart.

KABOOM! Sadly, I forgot to take a photo at this point, but I’m sure you can work out what needs to go where from the example!

Step 4 — Lay coloured stickers in order on the bottom row

Along the bottom row, place the coloured sticks in the order of the rainbow.

Laying the first colour Red on the number -6

Step 5— Place each colour in its other spots

In this step, we need to place each colour on its appropriate number (in other words, working in reverse back through the steps of the algorithm).

For example: the furthest most left colour is red, which was placed on the number -6. This means we must place a red sticker everywhere that we see a -6.

In my final picture, there’s another row along the bottom, which just reiterates the order of the colours as it looks nicer.

Placing colours on the appropriate numbers

Step 6 — Mark the pivoting numbers

Mark the pivoting colours, so that we can see how the algorithm partitions each branch by a colour.

More information on what a pivot is can be found in this really good article written by another Medium blogger.

In the example I’m following, the first pivot selected was Green (no. 3).

Define the First Pivot

--

--

George Marklow
George Marklow

Written by George Marklow

George is a software engineer, author, blogger, and abstract artist who believes in helping others to make us happier and healthier.

No responses yet