160 likes | 453 Views
Sorting Algorithms. Overview. Why is Sorting important? Sorting algorithms Comparing Sorting Algorithms. Why is Sorting important?. Computers often use large data sets Sorted data sets are easier to use Humans like sorted lists Our brains are comparison engines. Sorting algorithms.
E N D
Overview • Why is Sorting important? • Sorting algorithms • Comparing Sorting Algorithms
Why is Sorting important? • Computers often use large data sets • Sorted data sets are easier to use • Humans like sorted lists • Our brains are comparison engines
Sorting algorithms • Bubble Sort • Insertion sort • Merge Sort
Bubble Sort • Slowest Algorithm (Bubble sort has worst-case and average complexity both О(n2)) • Moves through the array n-1 times
Insertion Sort • Faster than Bubble Sort but still slow (The worst case insertion sort has a quadratic running time (i.e., O(n2)). • Works by moving an element to anywhere in the array it should be. • moves through the array once.
Merge Sort • 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
Comparing Sorting Algorithms • 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
What to Remember • 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
References • http://en.wikipedia.org/wiki/Bubble_sort • http://en.wikipedia.org/wiki/Insertion_sort • http://en.wikipedia.org/wiki/Merge_sort • http://en.wikipedia.org/wiki/Big_O_notation