This preview shows page 1-2-3-4-5-6-7-8-9-60-61-62-63-64-65-66-67-121-122-123-124-125-126-127-128-129 out of 129 pages.
61A Lecture 20Friday, October 14Friday, October 14, 2011Tree Recursion2Friday, October 14, 2011Tree RecursionTree-shaped processes arise whenever executing the body of a function entails making more than one call to that function.2Friday, October 14, 2011Tree RecursionTree-shaped processes arise whenever executing the body of a function entails making more than one call to that function.21, 2, 3, 4, 5, 6, 7, 8, 9,n:Friday, October 14, 2011Tree RecursionTree-shaped processes arise whenever executing the body of a function entails making more than one call to that function.2http://en.wikipedia.org/wiki/File:Fibonacci.jpg1, 2, 3, 4, 5, 6, 7, 8, 9,n:Friday, October 14, 2011Tree RecursionTree-shaped processes arise whenever executing the body of a function entails making more than one call to that function.2http://en.wikipedia.org/wiki/File:Fibonacci.jpg1, 2, 3, 4, 5, 6, 7, 8, 9,n:0, 1, 1, 2, 3, 5, 8, 13, 21,fib(n):Friday, October 14, 2011Tree RecursionTree-shaped processes arise whenever executing the body of a function entails making more than one call to that function.2http://en.wikipedia.org/wiki/File:Fibonacci.jpg1, 2, 3, 4, 5, 6, 7, 8, 9,n:0, 1, 1, 2, 3, 5, 8, 13, 21,fib(n): ... , 35Friday, October 14, 2011Tree RecursionTree-shaped processes arise whenever executing the body of a function entails making more than one call to that function.2http://en.wikipedia.org/wiki/File:Fibonacci.jpg1, 2, 3, 4, 5, 6, 7, 8, 9,n:0, 1, 1, 2, 3, 5, 8, 13, 21,fib(n): ... , 5,702,887 ... , 35Friday, October 14, 2011Tree RecursionTree-shaped processes arise whenever executing the body of a function entails making more than one call to that function.2http://en.wikipedia.org/wiki/File:Fibonacci.jpg1, 2, 3, 4, 5, 6, 7, 8, 9,n:0, 1, 1, 2, 3, 5, 8, 13, 21,fib(n): ... , 5,702,887 ... , 35 def fib(n):Friday, October 14, 2011Tree RecursionTree-shaped processes arise whenever executing the body of a function entails making more than one call to that function.2http://en.wikipedia.org/wiki/File:Fibonacci.jpg1, 2, 3, 4, 5, 6, 7, 8, 9,n:0, 1, 1, 2, 3, 5, 8, 13, 21,fib(n): ... , 5,702,887 ... , 35 def fib(n): if n == 1:Friday, October 14, 2011Tree RecursionTree-shaped processes arise whenever executing the body of a function entails making more than one call to that function.2http://en.wikipedia.org/wiki/File:Fibonacci.jpg1, 2, 3, 4, 5, 6, 7, 8, 9,n:0, 1, 1, 2, 3, 5, 8, 13, 21,fib(n): ... , 5,702,887 ... , 35 def fib(n): if n == 1: return 0Friday, October 14, 2011Tree RecursionTree-shaped processes arise whenever executing the body of a function entails making more than one call to that function.2http://en.wikipedia.org/wiki/File:Fibonacci.jpg1, 2, 3, 4, 5, 6, 7, 8, 9,n:0, 1, 1, 2, 3, 5, 8, 13, 21,fib(n): ... , 5,702,887 ... , 35 def fib(n): if n == 1: return 0 if n == 2:Friday, October 14, 2011Tree RecursionTree-shaped processes arise whenever executing the body of a function entails making more than one call to that function.2http://en.wikipedia.org/wiki/File:Fibonacci.jpg1, 2, 3, 4, 5, 6, 7, 8, 9,n:0, 1, 1, 2, 3, 5, 8, 13, 21,fib(n): ... , 5,702,887 ... , 35 def fib(n): if n == 1: return 0 if n == 2: return 1Friday, October 14, 2011Tree RecursionTree-shaped processes arise whenever executing the body of a function entails making more than one call to that function.2http://en.wikipedia.org/wiki/File:Fibonacci.jpg1, 2, 3, 4, 5, 6, 7, 8, 9,n:0, 1, 1, 2, 3, 5, 8, 13, 21,fib(n): ... , 5,702,887 ... , 35 def fib(n): if n == 1: return 0 if n == 2: return 1 return fib(n-2) + fib(n-1)Friday, October 14, 2011A Tree-Recursive Process3The computational process of fib evolves into a tree structureFriday, October 14, 2011A Tree-Recursive Process3fib(6)The computational process of fib evolves into a tree structureFriday, October 14, 2011A Tree-Recursive Process3fib(6)fib(4)The computational process of fib evolves into a tree structureFriday, October 14, 2011A Tree-Recursive Process3fib(6)fib(5)fib(4)The computational process of fib evolves into a tree structureFriday, October 14, 2011A Tree-Recursive Process3fib(6)fib(5)fib(4)fib(2)1fib(3)fib(1) fib(2)0 1The computational process of fib evolves into a tree structureFriday, October 14, 2011A Tree-Recursive Process3fib(6)fib(5)fib(4)fib(2)1fib(3)fib(1) fib(2)0 1fib(3)fib(1) fib(2)0 1fib(4)fib(2)1fib(3)fib(1) fib(2)0 1The computational process of fib evolves into a tree structureFriday, October 14, 2011A Tree-Recursive Process3fib(6)fib(5)fib(4)fib(2)1fib(3)fib(1) fib(2)0 1fib(3)fib(1) fib(2)0 1fib(4)fib(2)1fib(3)fib(1) fib(2)0 1The computational process of fib evolves into a tree structureFriday, October 14, 2011A Tree-Recursive Process3fib(6)fib(5)fib(4)fib(2)1fib(3)fib(1) fib(2)0 1fib(3)fib(1) fib(2)0 1fib(4)fib(2)1fib(3)fib(1) fib(2)0 1The computational process of fib evolves into a tree structureFriday, October 14, 2011A Tree-Recursive Process3fib(6)fib(5)fib(4)fib(2)1fib(3)fib(1) fib(2)0 1fib(3)fib(1) fib(2)0 1fib(4)fib(2)1fib(3)fib(1) fib(2)0 1The computational process of fib evolves into a tree structureFriday, October 14, 2011A Tree-Recursive Process3fib(6)fib(5)fib(4)fib(2)1fib(3)fib(1) fib(2)0 1fib(3)fib(1) fib(2)0 1fib(4)fib(2)1fib(3)fib(1) fib(2)0 1The computational process of fib evolves into a tree structureFriday, October 14, 2011A Tree-Recursive Process3fib(6)fib(5)fib(4)fib(2)1fib(3)fib(1) fib(2)0 1fib(3)fib(1) fib(2)0 1fib(4)fib(2)1fib(3)fib(1) fib(2)0 1The computational process of fib evolves into a tree structureFriday, October 14, 2011A Tree-Recursive Process3fib(6)fib(5)fib(4)fib(2)1fib(3)fib(1) fib(2)0 1fib(3)fib(1) fib(2)0 1fib(4)fib(2)1fib(3)fib(1) fib(2)0 1The computational process of fib evolves into a tree structureFriday, October 14, 2011A Tree-Recursive Process3fib(6)fib(5)fib(4)fib(2)1fib(3)fib(1) fib(2)0 1fib(3)fib(1) fib(2)0 1fib(4)fib(2)1fib(3)fib(1) fib(2)0 1The computational process of fib evolves into a tree structureFriday, October 14, 2011A Tree-Recursive Process3fib(6)fib(5)fib(4)fib(2)1fib(3)fib(1) fib(2)0 1fib(3)fib(1) fib(2)0 1fib(4)fib(2)1fib(3)fib(1) fib(2)0 1The computational process of fib evolves into a tree structureFriday, October 14, 2011A Tree-Recursive Process3fib(6)fib(5)fib(4)fib(2)1fib(3)fib(1) fib(2)0 1fib(3)fib(1) fib(2)0 1fib(4)fib(2)1fib(3)fib(1) fib(2)0 1The computational process of fib evolves into a tree structureFriday, October 14, 2011A Tree-Recursive
View Full Document