Bubble sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. Thealgorithm gets its name from the way smaller elements "bubble" to the top of the list.
defbubble_sort(arr):n=len(arr)foriinrange(n):forjinrange(0,n-i-1):ifarr[j]>arr[j+1]:arr[j],arr[j+1]=arr[j+1],arr[j]returnarr
The time complexity of bubble sort is O(n^2).
Top comments(0)
Subscribe
For further actions, you may consider blocking this person and/orreporting abuse