Real-world example of exponential time complexity

后端 未结 5 2011
南笙
南笙 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 04:47

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

    0 讨论(0)
  • 2021-01-30 04:51
    • 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.

    0 讨论(0)
  • 2021-01-30 05:01

    A pizza restaurant has several toppings to choose from

    • Pepperoni
    • Chilli peppers
    • Pineapple (don't knock it until you've tried it!)

    Customers may choose any combination of toppings or none at all for their pizza. Now consider an algorithm that finds every possible unique combination of toppings. This is an exponential algorithm with time complexity O(2^n).

    Look how the possible combinations grow (exponentially) when you add a new topping to the menu:

    0 toppings: 1 combination (no toppings at all)
    1 toppings: 2 combinations (none, a)
    2 toppings: 4 combinations (none, a, b, ab)
    3 toppings: 8 combinations (none, a, b, c, ab, ac, bc, abc)
    ...
    ...
    10 toppings: 1,024 combinations
    20 toppings: 1,048,576 combinations
    

    So with just 20 types of toppings, there are over 1 million possible combinations!

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-01-30 05:10

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

    0 讨论(0)
提交回复
热议问题