Skip to main content
### Number and algebra

### Geometry and measure

### Probability and statistics

### Working mathematically

### For younger learners

### Advanced mathematics

# Sorted

Compare the first two cards. If they are in the wrong order, swap them round.

Then compare the second and third card. If they are in the wrong order, swap them round.

Keep going through the pack. When you have finished, keep the cards in the new order and repeat the process from the beginning of the pack.

Repeat until you get all the way through the pack without doing any swaps.

The cards are now sorted.

First pass: compare the first two cards. Swap them if necessary.

Second pass: compare the second and third cards. Swap them if necessary. Then compare and swap the first two cards again if necessary.

Third pass: compare the third and fourth cards. Swap them if necessary. Then compare and swap second and third cards if necessary. Then compare and swap first and second cards if necessary.

Continue in the same way for the rest of the pack.

Go through the pack until you find the Ace. Swap it with the first card.

Then go through the pack until you find the Two. Swap it with the second card.

Then go through the pack until you find the Three. Swap it with the third card.

Repeat with the rest of the cards.

Put the first card down. Take the second card, and put it to the right or to the left of the first card, depending on whether it's higher or lower.

Then take the third card and place it correctly relative to the first two cards, making a space if necessary.

Take the fourth card and place it correctly relative to the first three cards, making a space if necessary.

Keep going until all the cards are in order in the new pile.

Take the first card of the pile. Sort the rest of the pack into numbers smaller than and numbers bigger than the number on the first card.

Put the first card down between these two sub-packs. Then sort each sub-pack of cards by taking the top one and sorting the rest into two sub-packs in the same way.

Keep going until there are no sub-packs with two or more cards.

**Notes and Background**

One way to get a sense of how sorting algorithms work is to watch animations, such as the ones on this website.

Thanks to Margaret for testing this problem.## You may also like

### Route to Root

### Triangle Incircle Iteration

### Vedic Sutra - All from 9 and Last from 10

Or search by topic

Age 14 to 18

Challenge Level

Take some numbered cards; between ten and twenty should be enough

(you could use a suit from a pack of playing cards).

Shuffle the cards.

Then organise your deck of cards into numerical order.

**What method did you use to put them in numerical order?**

Can you think of any other ways you could have sorted them?

Here are some different sorting algorithms you could try. You may find it easiest to lay the cards out in a line to keep track of their order and see what's happening at a glance.

**Bubble Sort**

Compare the first two cards. If they are in the wrong order, swap them round.

Then compare the second and third card. If they are in the wrong order, swap them round.

Keep going through the pack. When you have finished, keep the cards in the new order and repeat the process from the beginning of the pack.

Repeat until you get all the way through the pack without doing any swaps.

The cards are now sorted.

**Shuttle Sort**

First pass: compare the first two cards. Swap them if necessary.

Second pass: compare the second and third cards. Swap them if necessary. Then compare and swap the first two cards again if necessary.

Third pass: compare the third and fourth cards. Swap them if necessary. Then compare and swap second and third cards if necessary. Then compare and swap first and second cards if necessary.

Continue in the same way for the rest of the pack.

**Selection Sort**

Go through the pack until you find the Ace. Swap it with the first card.

Then go through the pack until you find the Two. Swap it with the second card.

Then go through the pack until you find the Three. Swap it with the third card.

Repeat with the rest of the cards.

**Insertion Sort**

Put the first card down. Take the second card, and put it to the right or to the left of the first card, depending on whether it's higher or lower.

Then take the third card and place it correctly relative to the first two cards, making a space if necessary.

Take the fourth card and place it correctly relative to the first three cards, making a space if necessary.

Keep going until all the cards are in order in the new pile.

**Quick Sort**

Take the first card of the pile. Sort the rest of the pack into numbers smaller than and numbers bigger than the number on the first card.

Put the first card down between these two sub-packs. Then sort each sub-pack of cards by taking the top one and sorting the rest into two sub-packs in the same way.

Keep going until there are no sub-packs with two or more cards.

Try each algorithm a few times, and keep a record of how many 'moves' or 'swaps' you do. You could work with a friend and 'race' against each other to see who sorts their pack the quickest.

If you are struggling to make sense of the written algorithms, here are some videos showing each algorithm being performed.

**Here are some questions to consider:**

- On average, which algorithm did you find to be quickest?
- What is the 'worst-case scenario' for each algorithm?
- How long would it take in the worst case?
- If you know a little about computer programming, think about how you might instruct a computer to perform these algorithms, and how long the computer would take to perform a sort of n objects using each algorithm.

One way to get a sense of how sorting algorithms work is to watch animations, such as the ones on this website.

Thanks to Margaret for testing this problem.

A sequence of numbers x1, x2, x3, ... starts with x1 = 2, and, if you know any term xn, you can find the next term xn+1 using the formula: xn+1 = (xn + 3/xn)/2 . Calculate the first six terms of this sequence. What do you notice? Calculate a few more terms and find the squares of the terms. Can you prove that the special property you notice about this sequence will apply to all the later terms of the sequence? Write down a formula to give an approximation to the cube root of a number and test it for the cube root of 3 and the cube root of 8. How many terms of the sequence do you have to take before you get the cube root of 8 correct to as many decimal places as your calculator will give? What happens when you try this method for fourth roots or fifth roots etc.?

Keep constructing triangles in the incircle of the previous triangle. What happens?

Vedic Sutra is one of many ancient Indian sutras which involves a cross subtraction method. Can you give a good explanation of WHY it works?