1. Introduction Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list, compares adjacent pairs and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted. The algorithm, which is a comparison sort, is named for the way smaller or larger elements "bubble" to the top of the list. Although the algorithm is simple, it is too slow and impractical for most problems even when compared to insertion sort. Bubble sort can be practical if the input is in mostly sorted order with some out-of-order elements nearly in position. 2. Flowchart START
def BubbleSort(Num)
for group1 in range(len(Num)-1,0,-1)
End
for i in range(group1)
Num[i]>Num[i+1] ?
temp = Num[i] Num[i] = Num[i+1] Num[i+1] = temp
BUBBLE SORT – DATA STRUCTURE | 1
3. Program
def BubbleSort(Num): for group1 in range(len(Num)-1,0,-1): for i in range(group1): if Num[i]>Num[i+1]: temp = Num[i] Num[i] = Num[i+1] Num[i+1] = temp
Numbers = [100,11,5,23,6,17,88,69,66,15] BubbleSort(Numbers) print(Numbers)
BUBBLE SORT – DATA STRUCTURE | 2
4. Data The data is 100, 11, 5, 23, 6, 17, 88, 69, 66 and 15 5. Result The result is will be sorted like this : 5, 6, 11, 15, 17, 23, 66, 69, 88 and 100
BUBBLE SORT – DATA STRUCTURE | 3