|
|
|
|
|
by throw149102
1525 days ago
|
|
I like to use the metaphor of driving somewhere, and trying to estimate when you're going to get there. Maybe you have a hotel reservation, and you want to make sure you don't get there too early nor too late. Then (with some times filled in for example): +---------------------------------------+-------------------------------+--------------------------------+----------------------------------------+
| . | Best Case (little/no traffic) | Average Case (average traffic) | Worst Case (car accident, snow-in etc) |
+---------------------------------------+-------------------------------+--------------------------------+----------------------------------------+
| Max time, upper bound (Big O) | 30 minutes | 45 minutes | 1 hour 20 minutes |
| Both min and max, tight bound (Theta) | 25 minutes | 35 minutes | 1 hour |
| Minimum time, lower bound (Omega) | 15 minutes | 25 minutes | 50 minutes |
+---------------------------------------+-------------------------------+--------------------------------+----------------------------------------+
So then you can start asking questions like - if I assume I'm in the average case, and I can show up earliest at 20 minutes from now, and show up latest at 50 minutes from now, can I guarantee that I will make it within that window? The answer in this case is yes, because our range is 25-45 minutes, so the earliest I can show up is in 25 minutes and the latest in 45 minutes.This also helps explain why Big O is generally more useful - we can almost always be early to something, but we can almost never be late to something. So showing up 5 minutes early usually is not a problem. It also shows why Theta is better than both - in this case, if we had this table we could completely ignore both the Big O row and Omega row, because Theta is a better bound for both min and max time. Of course, in algorithmic complexity we replace the times with functions in terms of some variables, usually just n. |
|
I think the most important thing that needs to be clarified though is that algorithmic complexity is first and foremost a function, `WorseCaseComplexity(size of input) = max number of steps for any input of that size`. This function is often then classed into a "complexity class" using O/Theta/Omega etc, but that is only done for the sake of easier comparison of complexities between algorithms.