Time complexity:
Worst-case: \(O(n^2)\)
Best-case: \(O(nlog(n))\)
Average-case: \(O(nlog(n))\)
Pick a random element (pivot) and partition the array.
[all numbers that are less than the pivot] pivot [all numbers that are greater than the pivot]
Time complexity:
Worst-case: \(O(n^2)\)
Best-case: \(O(nlog(n))\)
Average-case: \(O(nlog(n))\)
Pick a random element (pivot) and partition the array.
[all numbers that are less than the pivot] pivot [all numbers that are greater than the pivot]
Time complexity:
Worst-case: \(O(nlog(n))\)
Best-case: \(O(nlog(n))\)
Average-case: \(O(nlog(n))\)
Merge sort divides the array in half, sorts each of those halves, and them merges them back together.
Time complexity:
Worst-case: \(O(n^2)\)
Best-case: \(O(n^2)\)
Average-case: \(O(n^2)\)
Find the smallest element and move it to the front. Then, find the second smallest and move it.
Time complexity:
Worst-case: \(O(n^2)\)
Best-case: \(O(n)\)
Average-case: \(O(n^2)\)
Sort array elements in ascending order. If the first element is greater than the second element, swap the first two elements.
Then, we go to the “next pair” and so on.