Bubble Sort Algorithm
Bubble Sort Implementation (works by repeatedly swapping the adjacent elements if they are in wrong order.)
# Time-complexity : O(n^2), In-place, Can be made stable # Takes O(n^2) even when array already sorted (hence can be optimized by stopping the algorithm if inner loop didn’t cause any swap.)
Implementation
Bubble Sort optimized
# Best case: Array already sorted (O(n))