tree
block, we're going to point out various parts of the anatomy of a recursive procedure. The line numbers mentioned below refer to the picture at the end of this page.tree
block, we are subtracting 1 from the level
input of each recursive call, so that eventually the level
input will reach a value of 1, which is the condition for our Base Case. If we cannot reach our Base Case, our block will keep recursively calling itself forever, getting stuck in what we call an infinite loop. This is what happened with our tree
block before we modified it.Questions:
1. What would happen if we ran our tree
block with a level
input of less than 1? Think about it before you try it out.
2. Sometimes you can make a recursive procedure more elegant by having a smaller base case. In our tree
program, what would a "zero level" tree mean? Try rewriting tree
so that the base case is level=0
.