Zookal
Zookal

We’d love to hear any feedback or comment from you!

© 2011-2021 Zookal Pty Ltd

View question and answer

From our collection of questions and answers
Engineering · Computer Science
Question details

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!!!!

Answer
Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.

Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.