Bubble Search
Bubble search is one of the most common and basic sorting technique which is used to sort an array. Most common parameters are array which is to be sorted and a size of an array (optional).
Technique used in Bubble Sort
In bubble sort, sorting happens based on comparison between two element, like which one is greater or lesser.
Eg:
list = [2, 1] if list[0] > list[1]: list[0], list[1] = list[1], list[0]
Implementation of Bubble Sort!
def bubble_sort (array: list) -> list: for i in range(0, len(array) - 1): for j in range(0, len(array) - 1 - i): if array[j] > array[j + 1]: array[j], array[j+1] = array[j+1], array[j] return arr
Time complexity is O(N^2)
print(Happy Coding)
The above is the detailed content of Bubble Search... Swap (x, y);. For more information, please follow other related articles on the PHP Chinese website!