Sorting :
Sorting is one of the most commonly used concepts in programming. Sorting means arranging data in a specific order, such as ascending or descending.
Examples:
• Arranging vegetables based on their price
• Sorting students based on their marks
• Sorting employees based on their salaries
There are many sorting techniques available. In this first blog, I am starting with a simple sorting method and will move to other techniques in the coming blogs.
Bubble Sort
Scenario:
Imagine people standing in a line for a wedding photoshoot. The bride wants everyone to be arranged from shortest to tallest.
You compare two people standing next to each other. If the person on the left is taller, they swap places. This process is repeated until everyone is in the correct order.
This is how bubble sort works.
Situations to use bubble sort:
- When a student learning Python wants to understand how numbers move step by step during sorting.
- When most of the elements in the list are already in order, bubble sort works better.
- When the dataset is small and memory usage needs to be minimal.
Situations not to use bubble sort:
Consider the same wedding photoshoot scenario with 50 family members. Sorting by comparing two people at a time would take too long and is not efficient. In such cases, bubble sort is not suitable because it consumes more time.
Conclusion
Bubble sort is easy to understand and helpful for learning, but it is not the right choice for large datasets.
I will teach you using a new way of learning. Everyone has cooked Maggi at least once in their life. In the same way, I will show you how to cook code. Not in two minutes, but in a short, simple, and interesting way that is easy to understand and fun to follow.
Thank you for taking the time to read this blog. I will connect with you in the next blog with the implementation. Catch you soon.
If this explanation made bubble sort clear for you, let me know in the comments.
Your feedback helps me decide what to write next.
Top comments (0)