Sorting Algorithms

Madiwa Simon
3 min readAug 29, 2021

Ways of sorting in JavaScript.

Bubble Sort- Swapping comparing to integers and swapping them from left to right which ever is the bigger amount goes to the right, does it over again until it is done. Like bubbles rising to the surface.

Bubble sort is one of the slowest and the fastest sort there is, depends on the scenario of the array. It is also one of the simplest sorting method there is.

Selection Sort- Selection Sort is also one of the slowest in sorting algorithm. The best case and worst case scenario is at Big O(n²) Which is really slow because it will check every single digit in the array every single time to compare the minimum when it is done and found the minimum number in the array it will put it to the first place then do it again and this time it goes to the second place.

Insertion Sort- The same as the bubble sort but backwards and will find the smallest amount and swap it to the left until the end. It will do it over and over again until everything is sorted.

Merge Sort- It has worst and best case scenario of O(nlog n). It divides the array into smaller array comparing each element and sorting them from small to big. Until there is only one position they can go in and will merge again into one sorted array.

Quick Sort- Is one the most used sorting algorithm but in a more complex method. It will select a value in the middle of array called pivot and will select two numbers in the array and will compare it to the pivot that is selected and will put the lesser number to the left and greater number to the right. It will do it again and again until it is done comparing the whole array. It Similar to the Merge sort.

--

--