Lessons · Sorting
Sorting: putting things in order
Computers sort things all the time: your photos by date, a game's high scores, search results. Pick a way to sort and press play.
Press play to start.
- Step
- 0 / 0
- Compares
- 0
- Moves
- 0
- Guesses
- –
- Comparing
- Moving
- Held / smallest
- Pivot
- In final place
Try it offline · Bubble sort
The bubble line-up
- You need
- Time
Think about it
Count your compares
Make a tally mark every time you compare two things. Then type the same numbers into the lesson and see if you match the computer.
Which one is fastest?
Set Size to 64 and run each one. Watch the Compares counter. Computer scientists describe this with "Big O": it tells you how much more work there is when the list gets longer. n means how many numbers there are.
| Algorithm | Best | Average | Worst | Extra memory | Stable |
|---|
Stable means equal numbers keep the order they started in. That matters when you sort a class by surname and want students with the same surname to stay sorted by first name.