CP164 Lecture Notes - Lecture 9: Linear Search, Binary Search Algorithm, Data Element

75 views2 pages
School
Course
Professor

Document Summary

Write own search method by comparing (def _eq_) Can only compare food objects with other food objects (not strings) On have _first because there is no priority. Implementation: ex. if key_movie is in movie: (def_contains_ then python will know how to use in) define in the queue class. Add deepcopy to the value to not make a direct reference. Write own search to later in course do a binary search. For loop only stops when we hit end. But with while loop you can stop when condition is met. Searches for the first occurrence of key in the list. Private helper method - used only by other adt methods. Key - a partial data element (?) I - the index of key in the list, -1 if key is not found (int) #make loop as small as we can ( don"t put ifs inside body of loop) Linear search method is a private helper method.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents