CSCA08H3 Chapter Notes - Chapter 11: Linear Search, Insertion Sort, Binary Search Algorithm

46 views2 pages

Document Summary

L. index(value, [start, [stop]]) -> integer -- return first index of value. """return the index of the first occurrence of v in list l, or return len(l) if v is not in l. "" " i = 0. # keep going until we reach the end of l or until we find v. while i != len(l) and l[i] != v: i = i + 1 return i for loop version of linear search def linear_search(v, l): It"s linear cuz we have a set amount of stuff that needs to run. This technique is called binary search, because each step divides the remaining data into two equal parts: values that come before the one being looked for and values that come after it. Selection sort works by partitioning the list in two. The section at the front contains values that are now in sorted order; the one at the back contains values that have yet to be sorted.

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