What is Bubble Sort ? And why do we need this ?
Bubble sort is the simplest algorithm to sort any array.
In computer graphics it is popular for its capability to detect a very small error (like swap of just two elements) in almost-sorted arrays and fix it with just linear complexity (2n). For example, it is used in a polygon filling algorithm, where bounding lines are sorted by their x coordinate at a specific scan line (a line parallel to x axis) and with incrementing y their order changes .
ALGORITHM :-
1.) Firstly we have an unsorted list, which is to be sorted.
2.) Consider the first element of the list. Then compare it with the next element.
3.) If the second element is greator than the first element than swap them.
4.) If the second element is smaller than the first element, then we don't have to do anything.
5.) Going ahead, now after swap (may or may not), look for second element, if it is greator than the next element than swap it otherwise leave it as it is.
6.) Now by following the above step for all the elements. Now run the loop again and again, and see if first is greator than second than swap otherwise leave it. And so on until the whole list is sorted.
7.) At last, we will get the sorted list.
DATA STRUCTURE :-
Hope you guys understood this topic. Share it with your friends and help them learning Python. In the next tutorial, we will learn the insertion sort algoritms which is more fun.
Contact mail id - john.veer.utube@gmail.com
Contact us for any query.
Thank You for reading !

Comments
Post a Comment