CSC148H5 Lecture Notes - Lecture 11: American Broadcasting Company, Empty String, Erms

34 views4 pages

Document Summary

Csc148h5s - introduction to computer science (winter 2017) Solving a problem by reducing it to subproblems, then combining the subproblem solutions to solve the original problem. Subproblems must have the same structure as the original problem and be easier to solve. Subproblems are so simple that they can be solve directly (without reducing them harm) # binary example from the previous class def codes (r): Return all binary codes of length r. if r == 0 : return [ "" ] small = codes(r -1 ) lst = [] for item in small: lst. append(item+ "0" ) lst. append(item+ "1" ) return lst. It does small = codes(1-1) so, small = [""] lst becomes ["0", "1"] codes(1) returns ["0","1"] What does codes(2) do? small becomes ["0","1"] lst becomes ["00","01","10",11"] so codes(2) is correct? yes. Example 2: finding the length of a string.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents