Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python help!!! I need to write a few functions in Python. Write two versions of a factorial function. #This is the iterative version that uses

Python help!!!

I need to write a few functions in Python.

Write two versions of a factorial function.

#This is the iterative version that uses a loop with an accumulator. Given n, return n!.

# ifac

def ifac(n):

...

#This is a recursive solution where:

#rfac(n) = 1, if n=0

# =n * rfac(n-1), otherwise.

# rfac

def rfac(n):

...

#Permutations - Implement the function perm(n,r) that returns the number of ways to arrange r items out of a set of n items. # perm

def perm(n,r):

...

#Combinations - returns the number of ways to choose r items out of a set of n items where order does not matter. # comb

def comb(n,r):

...

#Fibonacci Numbers that returns the nth Fibonacci number. The fibonacci sequence starts with 0,1. Each successive number is calculated by summing the previous two numbers. This is a recursive function. # fib

def fib(n):

...

#Memoization - uses memoization to greatly speed up the calculation. Use a dictionary to memoize each value of fib(n) as they are computed. # mfib

def mfib(n):

...

#Pascal's Triangle - construct pascal's triangle, each number at a given (row, column) locationcan be computed by summing the two numbers above it. The numbers on the edges are always 1. The function below computes the number at the given (rwo, col) by using the formula above. This is a recursive function. The base case is when (row, col) corresponds to one of the edges. Otherwise, it sums the two values above. # pascal

def pascal(row, col):

...

#Memoization - make a new function called mpascal(row,col) that uses memoization to speed up the computation.

# mpascal

def mpascal(row, col):

...

Thanks in advance!!!!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions

Question

Question Can I collect benefits if I become disabled?

Answered: 1 week ago

Question

Question May I set up a Keogh plan in addition to an IRA?

Answered: 1 week ago