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

后端 未结 5 726
醉梦人生
醉梦人生 2021-02-01 03:19

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):

<         


        
5条回答
  •  不知归路
    2021-02-01 03:53

    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)

提交回复
热议问题