Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 250 February 16 - 20, 2009. Announcements 2/16 – In-lab Exercise 3 due 3/4 - Exam 2 Data Structures 1, 2, 3 are due Friday 3/6. However, those projects.

Similar presentations


Presentation on theme: "CSE 250 February 16 - 20, 2009. Announcements 2/16 – In-lab Exercise 3 due 3/4 - Exam 2 Data Structures 1, 2, 3 are due Friday 3/6. However, those projects."— Presentation transcript:

1 CSE 250 February 16 - 20, 2009

2 Announcements 2/16 – In-lab Exercise 3 due 3/4 - Exam 2 Data Structures 1, 2, 3 are due Friday 3/6. However, those projects will not be considered late as long as they are turned in by the end of the day 3/15.

3 Announcements Using Web-CAT to submit your assignments Data Structures 1, 2, and 3 will need to be submitted using Web-CAT, a new online submission mechanism. Please see ◦ http://www.cse.buffalo.edu/faculty/adrienne/SP 2009/cse250/Lectures/SubmissionUsingWeb- CAT.ppt

4 Recursion What do we know about recursion? A recursive function is one that calls itself. Recursive functions have: ◦ One or more base cases ◦ A recursive case

5

6 Recursive Linear Search public int linearSearch(Collection items, E toFind, int index) { if(items.isEmpty()) return -1; else if(items[index] == toFind) return index; else return linearSearch(items, toFind, index+1); }

7 Binary Search int binarySearch(Collection items, Elem_Type searchItem) { if(items.isEmpty()) return -1; else return binarySearchHelper(items, itemToLookFor, 0, items.size()); }

8 Binary Search Helper int binarySearchHelper(Collection items, Elem_Type searchItem, int start, int end){ if(start > end) return -1; else { int mid = start+end /2; if(items[mid] == itemToLookFor) return mid; else if (items[mid] < itemToLookFor) return binarySearchHelper(items, itemToLookFor, mid+1,end); else return binarySearchHelper(items, itemToLookFor, start, mid-1); }

9 Test Cases Come up with test cases for binary search

10

11 Trace Through Trace through test cases to uncover errors (code printed on previous slides fixes errors we found in lecture). Are there more? More testing could reveal more…

12

13 Heaps / Priority Queues

14

15

16

17

18

19

20

21


Download ppt "CSE 250 February 16 - 20, 2009. Announcements 2/16 – In-lab Exercise 3 due 3/4 - Exam 2 Data Structures 1, 2, 3 are due Friday 3/6. However, those projects."

Similar presentations


Ads by Google