Question
The purpose of this assignment is to reinforce the concept of recursion in our minds. This recursion assignment does not require coding. However, it does
The purpose of this assignment is to reinforce the concept of recursion in our minds. This recursion assignment does not require coding. However, it does require a detailed walk-thru with a snap-shot of the information on the stack at every call and the state of the data at every return.
The code below is a very simple example of a recursive function to compute the value of factorial (say 5).
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
Your output diagram should look something like the slide 15 of chapter 4 on Recursion:
Please do this assignment carefully, understanding what is going on every step of the way - it should be fun! By drawing the diagrams, depicting what the data looks like at each call, how each return works, will go a long way to understanding how recursion works. It is not all magic!
Stack Frames: Implementina Recursion toStr(10) 10 11 2 + 0 toStr(5) 5 11 2 toStr(2,2) base toStr(2//2,2) + convertString[2%2 toStr(5,2) toStr(2) 2 112 toStr(1) base 2 toStr(S//2.2) + convertString[S%2 toStr(10,2) n-10 base 2 toStr(10//2.2) + convertString[10%2]Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started