When is Big-O = x classified as inefficient?
Lets say we have a problem we implemented using X algorithm with O(n)
or O(log n)
or etc...
. When is the value of n
big enough that we must consider an alternative implementation? Let's see if i can explain myself a little better.
For n=10,000
O(n^2) = 100,000,000
O(n) = 10,000
O(Log n) = 4
. . .
Obviously the best algorithm will be the one with the lowest "Big-o".
So lets say we sort an array of length 5 using bubble sort, the result is 25, that's not that bad. But when is the result of the O notation so large that realistically w开发者_开发问答e must use another implementation.
When it's a bottleneck in your application.
But in general, aim for algorithms with lowest complexity, while also allowing ease of implementation.
A certain Big O complexity doesn't mean that you should always avoid it; you should shoot for algorithms of lower complexities, but O(n^2) where n is 12 is going to run plenty fast regardless of the fact that O(n^2) is usually considered a "bad" complexity.
O(n^2) doesn't automatically mean "too slow"; O(n log n) doesn't automatically mean "yay, this is fast". If a given algorithm runs too slowly, then you want to reduce its runtime, and you can often do this by reducing its complexity, but until it becomes a problem, don't sweat it.
A solution too inefficient when there is another solution that is lower Big-O, and thus more efficient.
When it is equivalent to
and alpha = 1.
精彩评论