Time Complexities of recursive algorithms

Posted by Peter on Stack Overflow See other posts from Stack Overflow or by Peter
Published on 2012-12-09T21:33:00Z Indexed on 2012/12/09 23:04 UTC
Read the original article Hit count: 232

Whenever I see a recursive solution, or I write recursive code for a problem, it is really difficult for me to figure out the time complexity, in most of the cases I just say its exponential? How is it exponential actually? How people say it is 2^n, when it is n!, when it is n^n or n^k.

I have some questions in mind, let say find all permutations of a string (O(n!)) find all sequences which sum up to k in an array (exponential, how exactly do I calculate). Find all subsets of size k whose sum is 0 (will k come somewhere in complexity , it should come right?).

Can any1 help me how to calculate the exact complexity of such questions, I am able to wrote code for them , but its hard understanding the exact time complexity.

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about data-structures