Bubble Sort | MLPro


Mon Oct 18 2021 17:26:40 GMT+0000 (Coordinated Universal Time)

Saved by @blurred_8216 ##python ##machinelearning

def bubbleSort(values):
    for i in range(len(values)):
        for j in range(len(values)-1):
            if values[j] > values[j+1]:
                values[j] ,values[j+1] = values[j+1], values[j]
    return values

-> Bubble sort is the simplest sorting algorithm in computer science: -> it simply compares every 2 adjacent elements and swaps them if they are not in order. -> This process is repeated unitll the whole list is sorted. This algorithm is discussed in almost all Computer Science -> classes, and the concept is tested in many tech company interviews for data scientists.