Class Notes (1,100,000)
US (480,000)
UW-Madison (5,000)
Lecture 40

COMP SCI 200 Lecture Notes - Lecture 40: Stack Overflow


Department
Computer Sciences
Course Code
COMP SCI 200
Professor
Marc Renault
Lecture
40

This preview shows half of the first page. to view the full 2 pages of the document.
Comp Sci 200- Lecture 40- Recursion
Recursion
○ Recursive method
■ A method that calls itself
■ Indirect

recursion- a method that calls another method (and
possibly others) that eventually calls the original method
○ Main components
■ Base case
● One or more cases that return a value with making a
recursive call
Reduction
● Break the problem into one (or more) recursive calls
● The sequence of calls must converge
to a base
○ Recursion vs iteration
Recursion
public static long factorial (int n) {
if (n == 0) {
return 1;
}
return n * factorial(n -1);
}
You're Reading a Preview

Unlock to view full version