Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have to write two Pascal\'s Triangle functions in python: Pascal\'s Triangle f

ID: 3826065 • Letter: I

Question

I have to write two Pascal's Triangle functions in python:

Pascal's Triangle function 1.

To construct Pascal's Triangle, each number at a given (row, column) location can be computed by summing the two numbers above it. The numbers on the edges are always 1.

Write a function called pascal(row, col) that computes the number at the given (row, col) by using the formula above. It's a recursive function. The base case is when (row, col) corresponds to one of the edges. Otherwise, it sums the two values above.

Pascal's Triangle function 2 using Memoization.

Make a new function called mpascal(row, col) that uses memoization to speed up the computation.

Explanation / Answer

def pascal(row, col):
if col == 0 or col == row:
return 1
return pascal(row-1, col -1) + pascal(row -1, col)

n = 10
for i in range(0, n):
for j in range(0, i+1):
print(pascal(i, j)),
print("")

code link: https://goo.gl/Ki8q8E