# Sorting Algorithms with Poker Cards

Some time ago, I needed my class to gain a basic understanding of sorting algorithms. After all, sorting is a classic in algorithmics that allows to consider many aspects (time complexity/memory usage). On the other hand, in practice all of them could rely on existing implementations in their daily life.

Thus I decided to let the students do the sorting *with poker cards instead of computers*.

## Required material

- four piles of 20 playing cards
- printed pseudocode of the four sorting algorithms
- stopwatches (any mobile phone will do).
- paper to write down time

## How to do it

- organize the material in four stations (each with a set of cards and one sorting algorithm)
- divide the class into groups
- ask them to cycle the stations, follow the instructions and measure time.
*Optional:* repeat the procedure with a small (10) and a larger (20) number of cards to get an idea of time complexity.

## The instructions

### Selection Sort

- Shuffle the cards.
- Lay them out in a row in front of you.
- Take the smallest card an put it on a separate pile.
- Look for the next smallest card and put it on top of the first.
- Repeat steps 3.and 4. until all cards are sorted.
- Measure the time you need for sorting all cards and write it down.

### Insertion Sort

- Shuffle the cards.
- Place them in a pile in front of you.
- Take the first card into your hand.
- Take the second card and put it next to the first,
so that the smaller one is to the left.
- Take the next card and put it into the correct position
beside the others.
- Repeat step 5. until all cards are sorted.
- Measure the time you need for sorting all cards and write it down.

### Bubblesort

- Shuffle the cards.
- Lay them out in a row in front of you.
- Look for a smaller card that is on the right adjacent to a bigger one.
- Exchange the two so that the smaller card is to the left.
- Repeat steps 3. and 4. until everything is sorted.
- Measure the time you need for sorting all cards and write it down.

### Mergesort

- Shuffle the cards.
- Divide them into two equal piles.
- Sorts both piles separately in your hand.
- Place the sorted piles face up in front of you,
so that the smallest card is on top.
- Place the smaller of the two visible cards on a third pile.
- Repeat step 5. until all cards are in the third, sorted pile.
- Measure the time you need for sorting all cards and write it down.

Download printable PDF

Download editable document