









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to asymptotic notation, including explanations of big o, big omega, and big theta, as well as examples and formal definitions. It also covers the addition, subtraction, and multiplication rules for these notations.
Typology: Slides
1 / 17
This page cannot be seen from the preview
Don't miss anything!










The knapsack problem is as follows: given a set of integers S = {s 1 , s 2 ,... , sn}, and a given target number T , find a subset of S which adds up exactly to T. For example, within S = { 1 , 2 , 5 , 9 , 10 } there is a subset which adds up to T = 22 but not T = 23. Find counterexamples to each of the following algorithms for the knapsack problem. That is, give an S and T such that the subset is selected using the algorithm does not leave the knapsack completely full, even though such a solution exists.
Algorithms are an important and durable part of computer science because they can be studied in a machine/language independent way. This is because we use the RAM model of computation for all our analysis.
We measure the run time of an algorithm by counting the number of steps, where: This model is useful and accurate in the same sense as the flat-earth model (which is useful)!
The best case complexity of an algorithm is the function defined by the minimum number of steps taken on any instance of size n. The average-case complexity of the algorithm is the function defined by an average number of steps taken on any instance of size n. Each of these complexities defines a numerical function: time vs. size!
Best, worst, and average are difficult to deal with precisely because the details are very complicated:
1 2 3 4......
It easier to talk about upper and lower bounds of the function. Asymptotic notation (O, Θ, Ω) are as well as we can practically deal with complexity functions. Docsity.com
(c)
f(n) c2*g(n)
n0 n
cg(n) c1g(n)
f(n)
n0 n
f(n) c*g(n)
n0 n (a) (b)
The definitions imply a constant n 0 beyond which they are satisfied. We do not care about small values of n.
3 n^2 − 100 n + 6 = Ω(n^2 ) because 2. 99 n^2 < 3 n^2 − 100 n + 6 3 n^2 − 100 n + 6 6 = Ω(n^3 ) because 3 n^2 − 100 n + 6 < n^3 3 n^2 − 100 n + 6 = Ω(n) because 1010
10 n < 3 n^2 − 100 + 6
3 n^2 − 100 n + 6 = Θ(n^2 ) because O and Ω 3 n^2 − 100 n + 6 6 = Θ(n^3 ) because O only 3 n^2 − 100 n + 6 6 = Θ(n) because Ω only
Multiplication by a constant does not change the asymptotics:
O(c · f (n)) → O(f (n)) Ω(c · f (n)) → Ω(f (n)) Θ(c · f (n)) → Θ(f (n))
But when both functions in a product are increasing, both are important:
O(f (n)) ∗ O(g(n)) → O(f (n) ∗ g(n)) Ω(f (n)) ∗ Ω(g(n)) → Ω(f (n) ∗ g(n)) Θ(f (n)) ∗ Θ(g(n)) → Θ(f (n) ∗ g(n))