Real-world example of exponential time complexity

我只是一个虾纸丫 提交于 2019-12-20 08:18:11

问题


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 other time complexities I have come up with (many of them taken from this SO question):

  • O(1) - determining if a number is odd or even
  • O(log N) - finding a word in the dictionary (using binary search)
  • O(N) - reading a book
  • O(N log N) - sorting a deck of playing cards (using merge sort)
  • O(N^2) - checking if you have everything on your shopping list in your trolley
  • O(infinity) - tossing a coin until it lands on heads

Any ideas?


回答1:


  • O(10^N): trying to break a password by testing every possible combination (assuming numerical password of length N)

p.s. why is your last example is of complexity O(infinity) ? it's linear search O(N) .. there are less than 7 billion people in the world.




回答2:


The brute force solution of the traveling salesman problem is O(n!) which is approximately O(N^N)




回答3:


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




回答4:


What about finding a subset of integers within a set such that their sum is a designated value X?

I believe this has complexity O(2^(n/2))



来源:https://stackoverflow.com/questions/7055652/real-world-example-of-exponential-time-complexity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!