Presentation is loading. Please wait.

Presentation is loading. Please wait.

S ORTING A LGORITHMS. O VERVIEW Why is Sorting important? Sorting algorithms Comparing Sorting Algorithms.

Similar presentations


Presentation on theme: "S ORTING A LGORITHMS. O VERVIEW Why is Sorting important? Sorting algorithms Comparing Sorting Algorithms."— Presentation transcript:

1 S ORTING A LGORITHMS

2 O VERVIEW Why is Sorting important? Sorting algorithms Comparing Sorting Algorithms

3 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

4 S ORTING ALGORITHMS Bubble Sort Insertion sort Merge Sort

5 B UBBLE S ORT Slowest Algorithm (Bubble sort has worst-case and average complexity both О ( n 2 )) Moves through the array n-1 times

6 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.

7 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

8 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

9 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

10 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

11 R EFERENCES 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


Download ppt "S ORTING A LGORITHMS. O VERVIEW Why is Sorting important? Sorting algorithms Comparing Sorting Algorithms."

Similar presentations


Ads by Google