Lecture 6 Flashcards
Why bother with sorting alogirthms?
The algorithms are quite small and manageable:
1) They can be implemented in a short period of time
2) They are relatively simple to analyse
How do u conduct Bubble sort?
1) Repeatdealy compare adjacent pairs of elements
2) Swap the elements in pair putting the smaller element first
3) Reapeat
What is Quick sort
Quicksort is a divide and conquer algorithm
Quicksort picks an element from the list as the pivot, and partitions the list into two pieces:
Those elements smaller than the pivot value (not necessarily in order)
Those elements larger than the pivot value (not necessarily in order)
Quicksort is then called recursively on both pieces
Time complexities of Bubblesort
Best=O(n)
Average and Worst= O(n^2)
Time complexities of Quicksort
Best and Average =O(nLog2(n))
Worse=O(n)
What is Radix Sort?
The Radix sort method works only on binary or integer data
Radix sort works by using a binary bucket sort for each binary digit
We first “sort” by the least significant bit
Split input into 2 sets based on the bit – those that have a 0 or those that have a 1
Otherwise, maintain the order…
Then proceed to the next least significant bit and repeat until we run out of bits…
O(nb) time complexity