csci112 – Eliminating Recursion with Stacks (Solution)

$ 20.99
Category:

Description

CSCI 112, Lab 6
File names: Names of files, functions, and variables, when specified, must be EXACTLY as specified. This includes simple mistakes such as capitalization.
Documentation: Each file should begin with a docstring that includes your name, the class number and name, the lab number, and a short description of the lab, as well as documentation pertinent to that particular file.
Translations: Translate each of the following recursive functions into “unnested” versions and into nonrecursive functions following the style of the functions discussed in class and available in the file stackrecursion.py. Put all the functions into a file called uncursion.py and unit tests for all of them into a file called uncursion_test.py.
Put everything into a folder names csci112lab06yourname, zip and turn into canvas.
The problems:
def func01(n): if n < 2:
return 3*n
else:
return 2*func01(n-1)
1.
1
2
3
4
5
def func02(n): if n < 2:
return 3*n
elif n < 6:
return n*n
else:
return 3 + 2*func02(n-2)
2.
1
2
3
4
5
6
7
def func03(n): if n < 2:
return 3*n
else:
return 3*func03(n-1) + 2*func03(n-2)
3.
1
2
3
4
5
def func04(n): if n < 2:
return 3*n elif n%2 == 1:
return 7 + func04(n – 3) else:
return func04(n-1) * 2*func04(n//2)
4.
1
2
3
4
5
6
7
1
def func05(a, b): if a == 0:
return b+3
elif b == 0:
return a*2
else:
return 2*a + 3*b + 4*func05(a-1,b) + 5*func05(a, b-1)
5.
1
2
3
4
5
6
7
2

Reviews

There are no reviews yet.

Be the first to review “csci112 – Eliminating Recursion with Stacks (Solution)”

Your email address will not be published. Required fields are marked *