| | |
Summary: O Notation (Big Oh)
We want to give an upper bound on the amount of time it takes to solve a problem.
defn: v(n) = O(f(n)) constants c and n0 such that |v(n)| c|f(n)| whenever n > n0
Termed complexity: has nothing to do with difficulty of coding or understanding, just time to execute.
Important tool for analyzing and describing the behavior of algorithms
Is an n2
algorithm always better than a n3
algorithm? No, it depends on the specific constants, but if n
is large enough, an O(n3
) is always slower.
Complexity Class: O(1), O(log n), O(n), O(n log n), O(n2
) O(2n
)
For small n, c may dominate.
Intractable: all known algorithms are of exponential complexity
Measuring Complexity
1. Additive Property: If two statements follow one another, the complexity of the two of them is
the larger complexity.
O(m) + O(n) = O(max(n,m))
2. If/Else: For the fragment
|