Are there any real O(n^n) algorithms?

What you have coded in your example is very similar to a depth first search. So, that’s one answer. A depth first search algorithm without any special characteristics ( like re-convergent paths that can be optimized out ), should be n^n. This is actually not a contrived example. Chess programs operate on the same algorithm. … Read more

Difference between O(n) and O(log(n)) – which is better and what exactly is O(log(n))?

It means that the thing in question (usually running time) scales in a manner that is consistent with the logarithm of its input size. Big-O notation doesn’t mean an exact equation, but rather a bound. For instance, the output of the following functions is all O(n): Because as you increase x, their outputs all increase linearly – if there’s … Read more

What is the big-O of the function (log n)^k

Any function whose runtime has the form (log n)k is O((log n)k). This expression isn’t reducable to any other primitive function using simple transformations, and it’s fairly common to see algorithms with runtimes like O(n (log n)2). Functions with this growth rate are called polylogarithmic. By the way, typically (log n)k is written as logk n, so the above … Read more

How to calculate time complexity of backtracking algorithm?

In short: Hamiltonian cycle : O(N!) in the worst case WordBreak and StringSegment : O(2^N) NQueens : O(N!) Note: For WordBreak there is an O(N^2) dynamic programming solution. More details: In Hamiltonian cycle, in each recursive call one of the remaining vertices is selected in the worst case. In each recursive call the branch factor decreases by 1. Recursion … Read more