How to efficiently calculate a row in pascal's triangle?
I'm interested in finding the nth row of pascal triangle (not a specific element but the whole row itself). What would be the most efficient way to do it? I thought about the conventional way to construct the triangle by summing up the corresponding elements in the row above which would take: 1 + 2 + .. + n = O(n^2) Another way could be using the combination formula of a specific element: c(n, k) = n! / (k!(n-k)!) for each element in the row which I guess would take more time the the former method depending on the way to calculate the combination. Any ideas? >>> def pascal(n): ... line = [1] .