Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Is there any real Algorithm with a time complexity O(n^n), that isn't just a gimmick?

I can create such an Algorithm, like computing n^n in O(n^n) / Θ(n^n):

long n_to_the_power_of_m(int n, int m) {     if(m == 0) return 1;     long sum = 0;     for(int i = 0; i < n; ++i)         sum += n_to_the_power_of_m(n, m-1);     return sum; } 

(needs more than 4 minutes to compute 10^10)

Or other way around: Are there any Problems, which cannot be solved better than in O(n^n)?

like image 920
Floern Avatar asked May 27 '11 18:05

Floern


People also ask

Is O 1 n possible?

No, this is not possible: As n tends to infinity in 1/n we eventually achieve 1/(inf), which is effectively 0. Thus, the big-oh class of the problem would be O(0) with a massive n, but closer to constant time with a low n.

Is O 0 possible?

There is no such thing as O(0) .

Which algorithm has O 2 n time complexity?

O(2n) An example of an O(2n) function is the recursive calculation of Fibonacci numbers. O(2n) denotes an algorithm whose growth doubles with each addition to the input data set.

What are o1 algorithms?

O(1) describes algorithms that take the same amount of time to compute regardless of the input size. For instance, if a function takes the same time to process ten elements and 1 million items, then we say that it has a constant growth rate or O(1) .


1 Answers

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. Each move there are n moves to consider ( i.e. branches ), and you search d moves deep. So that becomes O(n^d)

like image 126
Himadri Choudhury Avatar answered Sep 19 '22 19:09

Himadri Choudhury