Bubble sort facts for kids
Bubble sort is a simple way to put a list of items, like numbers, in order. It's often one of the first sorting methods taught to new students because it's easy to understand. However, it's not the fastest way to sort things compared to some other methods.
The name "Bubble sort" comes from how it works. Imagine bubbles in water: the lighter ones float to the top. In Bubble sort, items "bubble up" to their correct place in the list, like the biggest numbers moving to the end or the smallest numbers moving to the beginning.
Contents
How Bubble Sort Works

This sorting method looks at pairs of items that are right next to each other in a list. It starts at the beginning of the list and compares the first item with the second, then the second with the third, and so on.
Here's how it goes:
- It checks the first two items. If they are in the wrong order (for example, if you want to sort from smallest to largest, and the first item is bigger than the second), it swaps them.
- Then, it moves to the next pair: the second and third items. It compares them and swaps them if needed.
- This process continues all the way to the end of the list.
- After going through the whole list once, the largest (or smallest, depending on how you're sorting) item will have "bubbled" to its correct spot at one end.
- The algorithm then repeats this process for the remaining unsorted part of the list. It keeps doing this over and over until no more swaps are needed, which means the entire list is perfectly sorted!
Steps to Implement Bubble Sort
You can make a computer program do a bubble sort by following these steps:
- Imagine you have a "sorted" flag that starts as "true."
- Go through your list, looking at each pair of items that are next to each other.
- If you find a pair that is out of order (like 5 then 2, when you want 2 then 5), swap them. If you swap any items, set your "sorted" flag to "false."
- Keep repeating these steps from the beginning of the list. If you go through the entire list and the "sorted" flag is still "true" (meaning you didn't have to swap anything), then your list is completely sorted!
Related Sorting Methods
Images for kids
See also
In Spanish: Ordenamiento de burbuja para niños