CSC148H5 Lecture Notes - Lecture 13: If And Only If

53 views2 pages
4 May 2016
School
Course
Professor

Document Summary

Return 0 return 1 + count(s([:1]),c) return count(s(:[1]),c) #return len of s using recursion if s == "": return 1 + strlen(s[:1]) return 0. #return number of occurences of c in s if s == "": elif s == c: else: #*below 3 are practice problems for recursion def strlen(s): def count(s,c): def contains(s,c): #* start of todays lessom - tracing recursion lst = #list of int potentially nested nums = [] for element in lst: Linear search: check each individual object 1 by 1. Binary search: check by the half which contains the searched number. #good example of recursion, adds mid to list every time def guess(low,high,actual): def binary_search(lst,s): if isinstance(element, int): else: return max(nums) return [mid] mid = (low + high) //2 if mid == actual: elif actual < mid: else: Return true iff s is found in lst. >>> binary_search([1,2,3,4],2) nums. append(element) nums. append(rec_max(element)) return [mid] + guess(mid+1,high,actual) return [mid] + guess(low,mid-1,actual)

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