Friday, August 12, 2011

Finding time complexity for recursive algorithm?

Probably the + 2 comes from the fact that the line return factorial((n-1)*2) actually executes 2 expressions: first it calculates x= (n-1), then it calculates x*2, and then it calls the factorial function, which has the T(n-1) complexity. So in total it is T(n-1) + 2

No comments:

Post a Comment