@extends('template') @section('title') Lab 12: Fruitful Recursion @stop @section('content') # Lab 12: Fruitful Recursion ## [Worksheet Solutions](https://docs.google.com/document/d/1mdtdx5uTbnt1SF181y_Tm_vxm2vy5PEkZ3n7u_i4KvU/edit?usp=sharing) ## [Python Solutions](/content/labs/lab12/solutions) ## Summary + Part 0: Worksheet warm-up + Part 1: Simple Fruitful Recursion + Part 2: Branching Recursion + Part 3: Extra Exercises @include('/labs/_setup', ['folder' => 'lab12']) - Note that @include('/labs/lab12/_toc') ## Big Questions {.bigqs} - **In a fruitful recursive function, which function frames contribute to the value returned by the original function frame?**
Show Answer The answer here is "all of them." Although only the original function frame directly returns the result value, it will typically use information returned by other function frames to construct that value, so all of the function frames end up contributing to the eventual result somehow.
- **When writing a loop, we often need to initialize a counter or result variable before the loop starts. How can we do that in a recursive function?**
Show Answer You can't really do the same thing, since each function call frame gets its own variables. However, you can initialize something in the base case of your recursive function and then return it, making it available for the next-higher function call frame to modify and return, which ends up achieving the same effect.
@stop