

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


















9/16/
Lecture 9 Algorithms 2:Complexity
9/16/
9/16/
n elements
9/16/
between list elements and element to find
Is x5 comparisons okay too?
9/16/
behavior of the algorithms
we do one comparison for each of the n items
9/16/
such that |f(x)|
C|g(x)|
(Plus need to compare x
2
and x
algorithm G (g(x)) for large inputs
9/16/
x^ ) O(
x)?
9/16/
3
is
C|1000000 x
3
1000000 C x
2
(positive for positive x)
is a constant, and x can be more than thatconstant.
9/16/
( g(x) ) if there exist constants C and k
such that |f(x)|
C|g(x)|
algorithm G (g(x)) for large inputs
9/16/
14
( g(x) ) if f(x) is O( g(x) ) and f(x) is
g(x) )
algorithm G (g(x)) for large inputs
“big-theta”.
9/16/
9/16/
list[location] += 1; foreach location in list
list[location] *= 2;
(n)
( max(n,n) ) =
(n)
9/16/
1
in list
foreach location
2
in list
list[location
] *= list[location 1
foreach location in list
list[location] += 3;
9/16/
(g(x)): “f(x) is
(k): “a constant time algorithm”
(log(n)): “a logarithmic time algorithm”
(n): “a linear time algorithm”
(n
2 ): “a quadratic time algorithm”
(n
k^ ): “a polynomial time algorithm”
(k
n^ ): “a exponential time algorithm”
(n!): “a factorial time algorithm”