Quicksort Flashcards
What is divide and conquer?
It’s a recursion algorithm
To solve a problem using D&C, there are two steps:
1. Figure out the base case. This should be the simplest possible case.
2. Divide or decrease your problem until it becomes the base case.
What is quicksort?
It’s a sorting algorithm, faster than selection sort and used more in real life, that use divide and conquer technique
What is the pivot?
It’s the element that we use to sort in quick sort algorithm
What is partitioning?
When we use the pivot, the array divided into:
A sub-array of all the numbers less than the pivot
The pivot
A sub-array of all the numbers greater than the pivot
How does quick sort algorithm work?
- Pick a pivot.
- Partition the array into two sub-arrays: elements less than the pivot and elements greater than the pivot.
- Call quicksort recursively on the two sub-arrays.
What is the if O for quick sort?
In the best case and average case=> o(n log n)
In the worst case => o(n^2)