Skip to content

Latest commit

 

History

History
23 lines (16 loc) · 585 Bytes

File metadata and controls

23 lines (16 loc) · 585 Bytes

Bubble Sort

Write a function to sort an array of n elements.

Bubble Sort:

Bubble sort, sometimes referred to as sinking 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. The pass through the list is repeated until the list is sorted. The time complexity is O(n²) in the average case.

Input:

arr = [2,1,6,4,9,7,5]

Output:

arr = [1,2,4,5,6,7,9]

Time Complexity:

O(n²)