Data Structures and Algorithms
Data Structures and Algorithms
Aaron Bauer
Winter 2014
Previously, on CSE 373
Easier explanation: it adds each number once while doing little else
Examples:
– 4n + 5
– 0.5n log n + 2n + 7
– n3 + 2n + 3n
– n log (10n2 )
So (3n2+17) is in O(n2)
– 3n2+17 and n2 have the same asymptotic behavior
Definition:
g(n) is in O( f(n) ) if there exist constants
c and n0 such that g(n) ≤ c f(n) for all n ≥ n0
Definition:
g(n) is in O( f(n) ) if there exist constants
c and n0 such that g(n) ≤ c f(n) for all n ≥ n0
Definition:
g(n) is in O( f(n) ) if there exist constants
c and n0 such that g(n) ≤ c f(n) for all n ≥ n0
Definition:
g(n) is in O( f(n) ) if there exist constants
c and n0 such that g(n) ≤ c f(n) for all n ≥ n0
• Average case
– Sometimes only if you assume something about the
probability distribution of inputs
– Sometimes uses randomization in the algorithm
• Will see an example with sorting
– Sometimes an amortized guarantee
• Average time over any sequence of operations
• Will discuss in a later lecture
– Or power or dollars or …