Lecture12-Recursion-3pp

# n1 n n n n 1 n 1 n 1 n 2 n 2 n 2 n 3 3

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: computa,ons • Recursion is an elegant way of describing the computa5on of certain func5ons   Ex: the sum of the ﬁrst N natural numbers 1 + 2 + 3 . . . N ­1 + N ∑N = N + ∑N-1 ∑N-1 = N - 1 + ∑N-2 ∑N-2 = N - 2 + ∑N-3 ... ∑3 = 3 + ∑2 ∑2 = 2 + ∑1 ∑1 = 1 ∑1 ∑2 ∑3 ∑N-1 ∑N 5 Recursive Func,on Example • Suppose we want to calculate 237. We know that 237 is 23*236. If we know the solu5on for 236 we would know the solu5on for 237. 148035889 237? 6436343 279841 12167 23*6436343 23*279841 23*12167 236? 235? 234? 233? 529 23*529 232? 23 23*23 1 1 23*1 231? 230? 23* 148035889 = 3,404,825,447 6 2 13 ­11 ­04 237 = 23 * 236 = 23 * (23* 235) = 23 * (23* (23* 234)) = 23 * (23*(23*(23* 233))) = 23 * (23*(23*(23*(23*232))))= 23 * (23*(23*(23*(23*(23*231)))))= 23 * (23 *(23*(23*(23*(23*(23*230))))))= 23 * (23 *(23*(23*(23*(23*(23*1))))))= 23 * (23 *(23*(23*(23*(23*(23))))))= 23...
View Full Document

## This document was uploaded on 03/02/2014.

Ask a homework question - tutors are online