# notes11 - Goal of Asymptotle Analysis Find out how an...

This preview shows pages 1–2. Sign up to view the full content.

Find out how an algorithm behaves in the worst case and when n -> (infinity) The function O(f(n)) should be as small as possible example 7n -b is O(n) bust also O(n^2) or O(n^3) but we choose O(n) because it better discribes 7n-b process drop the lowest order terms and construct functions from the function: 7n-3 -> O(n) 8n^2 * log(n)+5n^2+n -> O(n^2log(n)) special cases: O(log n)->logarithmic time O(n)->linear time O(n^2)->quadratic time O(n^k)->polynomial time O(a^n)->exponential time (n>0) Bubble Sort: void bubblesort (int n, int* array){ for(int i=0;i<n-1;i++){ for(int j=0;j<n-i-1;j++){ int tmp = array[j]; array[j]=arrray[j++]; array[j+1]=tmp; } } } } -assume the operations check the array values and swap is done in O(1) In the worst case the swap and if statements are exectuted in (n-1)*n/2 = n^2/2- n/2=O(n^2) operations. Execution times Bubble sort: O(n^2) Heap sort O(n log(n)) Merge sort O(n log(n)) Stacks 2 basic methods: push(0) push items to top of the stack

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 02/02/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue University.

### Page1 / 6

notes11 - Goal of Asymptotle Analysis Find out how an...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online