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):
Any ideas?
Exponential Time Complexity: O(2^n) Algorithms with this time complexity are usually used in situations where you don't know that much about the best solution, and you have to try every possible combination or permutation on the data.
Exponential Time complexity denotes an algorithm whose growth doubles with each additon to the input data set. If you know of other exponential growth patterns, this works in much the same way. The time complexity starts off very shallow, rising at an ever-increasing rate until the end.
So, if computing 10 elements take 1 second, computing 100 elements takes 2 seconds, 1000 elements take 3 seconds, and so on. When using divide and conquer algorithms, such as binary search, the time complexity is O(log n).
By definition, the Space complexity of an algorithm quantifies the amount of space or memory taken by an algorithm to run as a function of the length of the input. While Time complexity of an algorithm quantifies the amount of time taken by an algorithm to run as a function of the length of the input.
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.
A pizza restaurant has several toppings to choose from
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With