Skip to content

Commit f4f0832

Browse files
committed
Quick sort README file added
1 parent 9e92b8b commit f4f0832

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Sorting/Quick Sort/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Quick Sort
2+
3+
**Quick sort** is based on the divide-and-conquer approach based on the idea of choosing one element as a pivot element and partitioning the array around it such that: Left side of pivot contains all the elements that are less than the pivot element Right side contains all elements greater than the pivot
4+
5+
It reduces the space complexity and removes the use of the auxiliary array that is used in merge sort. Selecting a random pivot in an array results in an improved time complexity in most of the cases.
6+
7+
Like Merge Sort, Quick Sort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot. There are many different versions of Quick Sort that pick pivot in different ways.
8+
9+
- Always pick first element as pivot.
10+
- Always pick last element as pivot (implemented below)
11+
- Pick a random element as pivot.
12+
- Pick median as pivot.
13+
14+
The principle of the quicksort algorithm is this:
15+
16+
- Pick a “pivot” element.
17+
- “Partition” the array into 3 parts:
18+
- First part: all elements in this part is less than the pivot.
19+
- Second part: the pivot itself (only one element!)
20+
- Third part: all elements in this part is greater than or equal to the pivot.
21+
- Then, apply the quicksort algorithm to the first and the third part. (recursively)
22+
23+
![Quick Sort](./images/quick-sort.gif)
24+
25+
#### Complexity Analysis
26+
- Worst Case - O(n<sup>2</sup>)
27+
- Average Case - O(nlogn)
28+
- Best Case - O(nlogn)
29+
30+
### More on this topic
31+
- [Quick Sort - Wikipedia](https://en.wikipedia.org/wiki/Quicksort)
32+
- [Quick Sort - KhanAcademy Tutorial](https://www.khanacademy.org/computing/computer-science/algorithms/quick-sort/a/overview-of-quicksort)
33+
- [Understanding Quicksort (with interactive demo)](http://me.dt.in.th/page/Quicksort/)
34+
- [Quick Sort - HackerEarch Tutorial](https://www.hackerearth.com/practice/algorithms/sorting/quick-sort/tutorial/)
35+
- [Computer science in JavaScript: Quicksort](https://www.nczonline.net/blog/2012/11/27/computer-science-in-javascript-quicksort/)
137 KB
Loading

0 commit comments

Comments
 (0)