Tuesday, 17 September 2013

Pascal's Triangle Algorithm Analysis

Pascal's Triangle Algorithm Analysis

Do you think the pseudocode below is correct for calculating pascal's
triangle? What would its time and space complexity be like? and how can I
calculate it?
pascal triangle(n){
list<list<int>> triangle // double list saving the triangle
triangle.get(0).add(1)
for(int i=1; i<n; i++){
for(int j=0; j<i; j++){
if(triangle.get(i-1).get(j)==null ||
triangle.get(i-1).get(j-1)==null)
triangle.get(i).add(1)
else
triangle.get(i-1).add(triangle.get(i-1).get(j)+triangle.get(i-1).get(j-1))
}
}
print(triangle)
}

No comments:

Post a Comment