Real-world example of exponential time complexity

后端 未结 5 2027
南笙
南笙 2021-01-30 04:09

I\'m looking for an intuitive, real-world example of a problem that takes (worst case) exponential time complexity to solve for a talk I am giving.

Here are examples for

5条回答
  •  暖寄归人
    2021-01-30 05:08

    A brute-force and naive n-queens problem's solution.

    You have to place n queens on a n*n board without them to be taken by others.

    while there are untried configs, go to next solution and test it

    Assuming every queen is on a given row, there are n possibilities for the queen to be placed and n for the (n-1) other queens (because duplicate rows are not checked).

    Therefore, you've got a O(n^n) complexity

提交回复
热议问题