Your pseudocode looks like it makes sense.
For the complexity
Your algorithm is trying to calculate each number of the triangle once. If we let each calculation be constant time complexity then we are doing:
sum(i) (0 -> n)
Please excuse the poor notation To clarify:
If n is 6 then we are going to iterate 6 + 5 + 4 + 3 + 2 + 1 times. This actual complexity can be simplified to:
(n + 1) * (n/2)
effectively
O(n^2)
Another way of looking at the complexity
You are essentially doing the area of a triangle in iterations which is b*h/2
. Well we know the height of Pascal's triangle to be n. The bottom of the triangle (or the base) has n numbers. Therefore, we are generating:
n^2/2
which has a complexity of O(n^2)