![SelectionSort.gif](<https://s3-us-west-2.amazonaws.com/secure.notion-static.com/91a35782-53a6-4698-9665-ea3cac498643/SelectionSort.gif>)
![BubbleSort.gif](<https://s3-us-west-2.amazonaws.com/secure.notion-static.com/2f86d596-4c7d-4541-838c-7d0183a57703/BubbleSort.gif>)
Quick sort is the main sorting algorithm people use.
Quick sort’s strength is that its average case is very fast.
It works by assigning a pivot point, then partitioning the array, so that all numbers below the pivot are on the left side, and all numbers above it are on the right side. Then you repeat the process on the left and right sides of the partition, until the entire thing is sorted.
Properties
![QuickSort.gif](<https://s3-us-west-2.amazonaws.com/secure.notion-static.com/478ae3d5-3254-416c-bff4-6236f46c1746/QuickSort.gif>)
![QuickSortCode.jpg](<https://s3-us-west-2.amazonaws.com/secure.notion-static.com/6f0435b9-04a5-4123-8c67-a58bc4342f59/QuickSortCode.jpg>)
!(left <= right)
Usage
Merge sort sorts an array by first splitting it into pieces, then sorting the pieces while remerging them.
Merge sort’s strength is that its worst case is consistently fast.
![MergeSort.gif](<https://s3-us-west-2.amazonaws.com/secure.notion-static.com/29809182-0db1-4772-a49b-b2a42f63cb7c/MergeSort.gif>)
Implementation
Merge sort is implemented recursively.
![MergeSort1.jpg](<https://s3-us-west-2.amazonaws.com/secure.notion-static.com/d68c5eeb-3d40-4a5c-a257-790416c90193/MergeSort1.jpg>)
- Take an array, `A`
- Get the size of the array, `n`
- **End the recursion if the array only has 1 element**. Otherwise:
- Find the **midpoint**, `n/2`
- **Create two new empty arrays**, `left` and `right`, to hold the left and right halves of A.
- Loop through `A` and **copy each element** to the `left` or `right` arrays.
- **Recursively recall the function** on the left and right halves of the array. This will repeatedly split up the array until you get pieces of 1.
- Once you get pieces of 1, start **merging them back together.**
![MergeSort2.jpg](<https://s3-us-west-2.amazonaws.com/secure.notion-static.com/996f1ba7-6b4e-4b9d-b563-c6cfe6cf9ea8/MergeSort2.jpg>)
left
and right
, and the original full-sized array, A
.left
and right
subarrays, until one of them is fully traversed.
When the pieces have been fully re-merged, they will also be fully sorted.
Usage