


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Slides for the couse of Programming Abstractions for Computer Science. Functional recursion
Typology: Lecture notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!



int Raise(int base, int exp) { if (exp == 0) return 1; else return base * Raise(base, exp-1); } } Base case } Recursive case
int Raise(int base, int exp) { if (exp == 0) return 1; else { int half = Raise(base, exp/2); if (exp % 2 == 0) return half * half; else return base * half * half; } }
int Raise(int base, int exp) { if (exp == 0) return 1; else if (exp == 1) return base; else if (exp == 2) return base * base; else if (exp == 3) return base * base * base; else return base * Raise(base, exp - 1);
int C(int n, int k) { if (k == 0 || k == n) return 1; else return C(n-1, k) + C(n-1, k-1); }