There is no algorithm that could determine the complexity of a program [in general]. It is part of the stopping problem - you cannot determine if any algorithm will stop or not. [You cannot evaluate if this is Theta(infinity) or something less than it]
Typically, algorithms typically O(n!) Call a recursive call in a loop with a decreasing range, while O(2^n) algorithms call a recursive call twice in each call.
Note Not all algorithms that call a recursive call twice are O(2^n) - quicksort is a good example for the O(nlogn) algorithm, which also calls a recursive call twice.
EDIT: For example:
SAT brute force solution O(2^n) :
SAT(formula,vars,i): if i == vars.length: return formula.isSatisfied(vars) vars[i] = true temp = SAT(formula,vars,i+1) //first recursive call if (temp == true) return true vars[i] = false return SAT(formula,vars,i+1) //second recursive call
Find all the permutations: O(n!)
permutations(source,sol): if (source.length == 0): print sol return for each e in source: sol.append(e) source.remove(e) permutations(source,sol) //recursive call in a loop source.add(e) sol.removeLast()
source share