Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 280 Data Structures Professor John Peterson. Homework #1 Remember: this is due by class Wednesday! Ask questions now or by /wiki

Similar presentations


Presentation on theme: "CS 280 Data Structures Professor John Peterson. Homework #1 Remember: this is due by class Wednesday! Ask questions now or by /wiki"— Presentation transcript:

1 CS 280 Data Structures Professor John Peterson

2 Homework #1 Remember: this is due by class Wednesday! Ask questions now or by email/wiki http://wiki.western.edu/mcis/index.php/C IS280/f07/homework1

3 Dominating Terms The big idea behind Big-O notation is that when you add complexities, one term may dominate the other. That is, once n has reached some value, one complexity is ALWAYS bigger than another. Example: O(n 2 ) + O(n) = O(n 2 + n) = O(n 2 )

4 A Complexity Ladder O(1) O(log(n)) O(n) O(n log(n)) O(n 2 ) O(2 n ) There are lots more complexities “between the cracks” but these are the ones that we’ll be seeing this term.

5 Demo: Excel Complexity.xls

6 Insertion Sort Complexity What is the complexity of insertion sort? insertionSort(array A) for i <- 1 to length[A]-1 do value <- A[i] j <- i-1 while j >= 0 and A[j] > value do A[j + 1] = A[j]; j <- j-1 A[j+1] <- value t

7 Selection Sort Here’s another sort algorithm: Void selectSort(Sortable s) { for (int i = 0; i < s.size()-1; i++) for (int j = i+1; j < s.size(); j++) if (s.gtr(i,j)) s.swap(i,j); } What is the complexity here in the best and worst cases?

8 Dictionary Lookup Suppose we know that array a is in sorted order: Boolean present(key,a) { int low = 0; int high = a.length-1; while (low <= high) { int mid = (low + high)/2; if (a[mid] == key) return true; if (a[mid] < key) low = mid + 1 else high = mid-1 } return false; } What is this complexity of this? Why?


Download ppt "CS 280 Data Structures Professor John Peterson. Homework #1 Remember: this is due by class Wednesday! Ask questions now or by /wiki"

Similar presentations


Ads by Google