S ORTING A LGORITHMS
O VERVIEW Why is Sorting important? Sorting algorithms Comparing Sorting Algorithms
W HY IS S ORTING IMPORTANT ? Computers often use large data sets Sorted data sets are easier to use Humans like sorted lists Our brains are comparison engines
S ORTING ALGORITHMS Bubble Sort Insertion sort Merge Sort
B UBBLE S ORT Slowest Algorithm (Bubble sort has worst-case and average complexity both О ( n 2 )) Moves through the array n-1 times
I NSERTION S ORT Faster than Bubble Sort but still slow (The worst case insertion sort has a quadratic running time (i.e., O( n 2 )). Works by moving an element to anywhere in the array it should be. moves through the array once.
M ERGE S ORT Better algorithm ( O ( n log n )) and can be done recursively Break the array into small parts and sort. When the small parts are reassembled, put them in order
C OMPARING S ORTING A LGORITHMS In CS we use O() notation (big 'O' notation) It describes the limiting behavior of the function when the argument tends towards a particular value or infinity
S OME O() N OTATIONS NotationNameExample O(1)ConstantChecking a number is even or odd O(log n)LogarithmicFinding an item in a sorted array O(n)LinearFinding an item in an unsorted array O(n 2 )QuadraticBubble Sort
W HAT TO R EMEMBER There are many types of sorting algorithms For small data sets, anything is probably quick enough For large data sets, algorithm complexity becomes very important
R EFERENCES