Running time of algorithm A is at least O(n²) – Why is it meaningless?

T(n): running time of Algo A. We just care about the upper bound and lower bound of T(n) The statement: T(n) >= O(n^2) Upper bound: Because T(n) >= O(n^2), then there’s no information about upper bound of T(n) Lower bound: Assume f(n) = O(n^2), then the statement: T(n) >= f(n), but f(n) could be anything that is “smaller” than n^2 , Ex: constant, n,…, So there’s no conclusion … Read more

What is O(log(n!)) and O(n!) and Stirling Approximation

O(n!) isn’t equivalent to O(n^n). It is asymptotically less than O(n^n). O(log(n!)) is equal to O(n log(n)). Here is one way to prove that: Note that by using the log rule log(mn) = log(m) + log(n) we can see that: Proof that O(log(n!)) ⊆ O(n log(n)): Which is less than: So O(log(n!)) is a subset of O(n log(n)) Proof that O(n log(n)) ⊆ O(log(n!)): Which is greater … Read more

Are there any real O(n^n) algorithms?

What you have coded in your example is very similar to a depth first search. So, that’s one answer. A depth first search algorithm without any special characteristics ( like re-convergent paths that can be optimized out ), should be n^n. This is actually not a contrived example. Chess programs operate on the same algorithm. … Read more

Difference between O(n) and O(log(n)) – which is better and what exactly is O(log(n))?

It means that the thing in question (usually running time) scales in a manner that is consistent with the logarithm of its input size. Big-O notation doesn’t mean an exact equation, but rather a bound. For instance, the output of the following functions is all O(n): Because as you increase x, their outputs all increase linearly – if there’s … Read more

How are the following functions O(N^3)?

Do you know, f(n) = O(g(n)) implies f(n) <= constant* g(n), right? In other words, it means, when you plot the graph of f(n) and g(n) then after some value of, g(n) will always be more than f(n). Here g(n) is N^3 and remaining comes in f(n). Now, N^3 is always >= options a, b, c. hence answer id D 🙂 Edit: Following statements are true, n=O(n) n=O(n^2) n=O(n^3) But only n = O(n) is tight upper bound and that is what … Read more