Skip to content

Instantly share code, notes, and snippets.

View increDul0us's full-sized avatar
🎯
Focusing

incredulous increDul0us

🎯
Focusing
  • Singapore
  • 01:29 (UTC +08:00)
View GitHub Profile
### Keybase proof
I hereby claim:
* I am incredul0us on github.
* I am incredulous (https://keybase.io/incredulous) on keybase.
* I have a public key ASCDD7aRdWc3glCXBzb8LdxhNvVj4h1yaBKNfRAqCSMT2Qo
To claim this, I am signing this object:
h### Keybase proof
I hereby claim:
* I am incredul0us on github.
* I am incredulous (https://keybase.io/incredulous) on keybase.
* I have a public key ASCDD7aRdWc3glCXBzb8LdxhNvVj4h1yaBKNfRAqCSMT2Qo
To claim this, I am signing this object:
@increDul0us
increDul0us / Quicksort.md
Last active July 13, 2019 01:09
Quicksort

Quicksort ✂️

Quicksort (sometimes called partition-exchange sort) is an efficient sorting algorithm, serving as a systematic method for placing the elements of an array in order. Hence, Quicksort can give the minimum number of swaps required to sort an array in ascending order with the permission of only swapping two elements at a time.

The minimum number of swaps required to sort an array in ascending order using quick sort is O(n log n) where n is the number of elements in the array.

How Quicksort works

  1. Select an element as a pivot (preferably the rightmost or last index of the array).
  2. Partition the array into two subarrays such that all values lesser than the pivot are positioned at the left of the pivot and all values greater than the pivot are positioned at the right of the pivot.
  3. We then choose another pivot each in the subarrays and perform same action as step 2. This will be done until a single item array is reached.