This preview shows pages 1–6. Sign up to view the full content.
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 = aaaa (n times) Recursive definition: a = 1, a n+1 = aa 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
This note was uploaded on 01/10/2010 for the course CS 2022 taught by Professor Crandall during the Fall '08 term at Cornell University (Engineering School).
 Fall '08
 CRANDALL

Click to edit the document details