Skip to main content

Pascal's Triangle

Definition​

Pascal's Triangle Algorithm generates Pascal's triangle, a triangular array of binomial coefficients. It is a mathematical concept used in various fields, including combinatorics and algebra. The algorithm efficiently calculates the coefficients without directly computing factorials or using recursive methods

Practice​

generatePascalsTriangle(numRows):
triangle = []
for row from 0 to numRows-1:
newRow = []
for col from 0 to row:
if col is 0 or col is row:
newRow.append(1) // First and last elements are always 1
else:
// Calculate element by summing elements above and above to the left
newElement = triangle[row-1][col-1] + triangle[row-1][col]
newRow.append(newElement)
triangle.append(newRow)
return triangle