I’ve seen a few interesting discussions recently debating whether or not a given (“hard”) problem has at-best an 2^n or n! known solution.
My question is, aside from actually walking through the algorithm and seeing the growth rate, is there a heuristic for quickly spotting one versus the other? Ie. are there certain quickly-observable properties of an algorithm that make it obviously one or the other?
Related discussions:
There is no algorithm that can determine a complexity of a program [at all]. It is a part of the Halting Problem – you cannot determine if a certain algorithm will stop or not. [You cannot estimate if it is
Theta(infinity)or anything less then it]As a rule of thumb – usually
O(n!)algorithms are invoking recursive call in a loop with a decreasing range, whileO(2^n)algorithms invoke a recursive call twice in each call.Note: Not all algorithms that invokes a recursive call twice are
O(2^n)– a quicksort is a good example for anO(nlogn)algorithm which also invokes a recursive call twice.EDIT: For example:
SAT brute-force solution
O(2^n):Find all permutations:
O(n!)