Sorting Algorithms
Bubble Sort: Works by repeatedly swapping the adjacent elements if they are in the wrong order. Not suitable for large data sets. In this algorithm, traverse from left and compare adjacent elements and the higher one is placed at right side. In this way, the largest element is moved to the rightmost end at first. This process is then continued to find the second largest and place it and so on until the data is sorted. def bubbleSort(arr): n = len (arr) # Traverse through all array elements for i in range (n-1): swapped = False # Last i elements are already in place for j in range ( 0 , n - i - 1 ): # Traverse the array fr...
Comments
Post a Comment