Bubble Sort
-
Simple sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order.
-
It gets its name because smaller elements “bubble” to the top (beginning of the list) while larger elements “sink” to the bottom (end of the list) after each iteration.
-
The algorithm iterates through the list multiple times until no more swaps are needed, indicating that the list is sorted.
-
Bubble sort has a time complexity of O(n^2) in the worst-case scenario, making it inefficient for large lists but suitable for small datasets or educational purposes due to its simplicity.
-
Despite its inefficiency, bubble sort is easy to understand and implement, making it a common example for teaching sorting algorithms and computer science concepts.
Insertion Sort
-
Sorting by comparison and insertion of elements based on adjacent elements
- Time complexity
- Worst Case O(N^2)
- Best Case O(1)
- Somewhat inaccurate in first few iterations
Quicksort
-
Sorting by pivot. Pivot finds its position along the line. This splits array into two. Qucksort is called recursively and resulting subarrays are also quicksorted
-
Time complexity
- worst case scenario O(NlogN)
Merge Sort
- Time complexity O(NlogN)
- Split arrays into groups of 2. Then sort each group, then combine sort each time multiplying size by 2 (4, 8, 16, …)
Selection sort
- Move through the list, and select the smallest value to swap with the front.
- O(N^2) always