This commit is contained in:
2023-09-22 09:51:10 -04:00
commit 1af8bd1e54
32 changed files with 346400 additions and 0 deletions

22
14-quicksort/README.md Normal file
View File

@ -0,0 +1,22 @@
Quicksort
=========
Wikipedia on [Quicksort](http://en.wikipedia.org/wiki/Quicksort).
![quicksort gif](http://upload.wikimedia.org/wikipedia/commons/6/6a/Sorting_quicksort_anim.gif)
#### Algorithm
Another divide-and-conquer algorithm, Quicksort works by picking a pivot point, or a value in the array, and reordering all the elements with values less than the pivot to the front of it, and all values greater than the pivot to the back. This is called the partition operation, and upon completion the pivot point is in its correct position.
You then recursively apply the same steps to each sub array - the elements smaller than the last pivot, and the elements larger than the last pivot.
Your base case is when a sub array is length 1 or 0.
#### The Pivot
Unsure of where to set the pivot? Read under the header "Implementation issues" on the Wikipedia.
#### Implementation
Write a function, `quicksort()` that takes an unsorted `list` and returns a sorted `list`. You may want to use some helper functions to partition.

View File

@ -0,0 +1,9 @@
def quicksort(list):
def assertion(actualAnswer, expectedAnswer):
print("Your answer: " + str(actualAnswer))
print("Expcted answer: " + str(expectedAnswer))
print(actualAnswer == expectedAnswer)
assertion(quicksort([4, 2, 5, 8, 6]), [2, 4, 5, 6, 8])