CSC148H5 Lecture Notes - Lecture 4: American Broadcasting Company

45 views8 pages
29 Jan 2018
School
Course
Professor

Document Summary

Recursion. n! is as simple as induction gets. factorial(n) = {1 if n <= 1, n(n-1)! otherwise example: = 1 now we go backwards 1=> 2=> 6 so it is equal to 6 def fact(n): if n <= 1: return 1 return n*fact(n-1) it worked by following the example. =3 *(return of fact(2)) fact(2) = 2*(return of fact(1)) fact(1) = 1. ###### two things to do####: identify the base case(s) example: 1 was the base case at the begininng: figure out the recursive step. Example fibonacci sequence: f1 f2 f3 f4 f5fn. Fn = { fn = 1 if n <= 1 ,fn-1 + fn-2 def fib(n): if n <= 1: return 1 return fib(n-1) + fib(n-2) >>> fib(40) this doesnt work because the time is so far off: recursion is known as a threshold concept. You can"t go back to how you used to think about cs: recursion is a problem-solving approach.

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

Related Questions