DOC PREVIEW
Berkeley CS 61A - RecursionDiscussion

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Recursion Discussion Notes● Midterm Surveys!Reminders:● Midterm project progress reports are due Sun 10/20 11:55pm.● Beyond Block 1st Session Thurs 10/24 79pm, 306 Soda.○ Bring your own computers!● Midterm Review Sun 10/27 123PM, 2050 VLSB.1. Factorial (could skip to gcd)● Breakdown fact(5) into its recursive calls:fact(5) = 5 x fact(4) = 5 x 24 = 120fact(4) = 4 x fact(3) = 4 x 6 = 24fact(3) = 3 x fact(2) = 3 x 2 = 6fact(2) = 2 x fact(1) = 2 x 1 = 2fact(1) = 1 x fact(0) = 1 x 1 = 1fact(0) = 12. Greatest common divisorgcd(27, 9) = gcd(9, 27 % 9)= gcd(9, 0)= 9gcd(259, 111) = gcd(111, 259 % 111) 259  222 = 37 = gcd(111, 37) 111 = 37 * 3 = gcd(37, 0) = 37gcd(10, 3) = gcd(10, 10 % 3) = gcd(10, 1) = gcd(1, 10 % 1) = gcd(1, 0) = 13. Fibonacci sequencefib(n) = 0 if n = 01 if n = 1fib(n  1) + fib(n2) if n > 12 ^ 2 = 42 ^ 3 = 82 ^ 4 = 162 ^ 5 = 32● Runtime6. Memoization: How can we make Fibonacci linear + recursive?● Take a look at the tree, is there any repetition?● How can we avoid recalculating things we’ve already calculated?● Memoization AKA tabling● How can we add this to our current fibonacci code?7. Practice Problem Palooza● Define length of list without using list● Define multiply without using multiply● Define mod without using mod● Define palindrome


View Full Document
Download RecursionDiscussion
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view RecursionDiscussion and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view RecursionDiscussion 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?