CSE 214 Lecture Notes - Lecture 6: Dynamic Programming

21 views4 pages

Document Summary

A method is recursive if it calls itself. A recursive method should contain a stopping case or base case that is not recursive (without it, the method would never end) The recursive call(s) should be for simpler versions of the same problem. When a method calls another method (even itself), an activation record is stored on the system stack. Where to return when the called method ends. When a method returns, it uses the top activation record on the system stack to restore the conditions before the method call. Temporary storage for local variables including parameters if any. 9 public int factorial(int n){ if(n == 0){ return 1; int x = factorial(n-1); //return location b return n * x; result = factorial(4) //return location a. 6 public int fib(int n){ if(n == 0 || n == 1){ return n; int x = fib(n-1); int y = fib(n - 2) 9 return (x + y); result = fib(4);

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