This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Recursion is a powerful technique for specifying sets, functions, and programs A recursive function is a function that refers to itself Many algorithms can be written more compactly, easily, elegantly using recursion Early languages (e.g. Fortran) did not support recursion C and most other modern languages do Recursion is possible because of the execution stack Recursion example Example: computing positive integral powers a n = a·a·a···a (n times) Recursive definition: a = 1, a n+1 = a·a n int power(int base, int exp) { if(exp == 0) return 1; else return base*power(base, exp1); } int main(void) { printf(“%d\n”, power(5, 2)); return 0; } Lecture 4 today Last week: Things you already knew. This week: Things you come to this class for. Drop deadline: Today!...
View
Full Document
 Fall '08
 CRANDALL
 Recursion, Int Exp

Click to edit the document details