










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
During the study of discrete mathematics, I found this course very informative and applicable.The main points in these lecture slides are:Greedy Algorithms, Step of Algorithm, Suboptimal Algorithm, Order of Growth Terminology, Polylogarithmic, Complexity of Problems, Search Problem, Sorting Problem, Worst-Case Time Complexity, Approximate Solution
Typology: Slides
1 / 18
This page cannot be seen from the preview
Don't miss anything!











2
Greedy algorithms make the “best” choice at each step of the algorithm.
Greedy algorithms do not “backtrack,” or reconsider previous decisions.
Example: Making change in the fewest number of coins (US currency). Greedy algorithm: Starting with largest coins, use as many as possible before moving to next largest denomination.
4
Problem: Assign meeting to conference rooms Policy: In ascending order of room capacity, assign the largest remaining meeting that can be held in the room.
Meeting 1: 70 Meeting 2: 46 Meeting 3: 125 Meeting 4: 110 Meeting 5: 30 Meeting 6: 87
Room F 50 Room E 75 Room D 100 Room B 150 Room C 150 Room A 200
M2, OK M1, OK M6, OK M3, OK M4, OK M5, OK
Just one of many algorithms.
5
O(1) Constant O(log n) Logarithmic (c ∈ v) O(logc^ n) Polylogarithmic (c ∈ Z +^ ) O(n) Linear O(n c) Polynomial (c ∈ Z +^ ) O(c n^ ) Exponential (c ∈ Z +^ ) O(n!) Factorial
Best
Worst
7
Intractable: Problems that are not tractable.
Example: Traveling salesperson problem Wide use of greedy algorithms to get an approximate solution. For example under certain circumstances, you can get an approximation that is at most double the optimal solution.
8
NP: Solvable problems whose solution can be
The most famous unproven conjecture in computer
P ⊂ NP rather than P = NP
10
Big-O notation is used to express the time complexity of an algorithm. It is a statement about an algorithm, not a machine! We can assume that any operation requires the same amount of time. The time complexity of an algorithm can be described independently of the software and hardware used to implement the algorithm.
11
Def .: Let f , g be functions with domain R ≥0 or N and codomain R.
f(x) is O(g(x)) if there are constants C and k s.t. ∀x > k, |f (x)| ≤ C ⋅ |g (x)|
between f & g.
13
To prove that a function f(x) is O(g(x)) Find values for k and C- not necessarily the smallest one, larger values also work!! It is sufficient to find a certain k and C that works In many cases, for all x ≥ 0, if f(x) ≥ 0 then |f(x)| = f(x)
Example: f(x) = x 2 + 2x + 1 is O(x 2 ) for C = 4 and k = 1
14
Show that f(x) = x^2 + 2x + 1 is O(x 2 ).
When x > 1 we know that x ≤ x^2 and 1 ≤ x^2 then 0 ≤ x^2 + 2x + 1 ≤ x^2 + 2 x 2 + x^2 = 4 x^2 so, let C = 4 and k = 1 as witnesses, i.e., f(x) = x 2 + 2x + 1 < 4 x 2 when x > 1
Could try x > 2. Then we have 2x ≤ x^2 & 1 ≤ x^2 then 0 ≤ x^2 + 2x + 1 ≤ x^2 + x^2 + x^2 = 3 x 2 so, C = 3 and k = 2 are also witnesses to f(x) being O(x^2 ). Note that f(x) is also O(x 3 ), etc.
16
Show that f(n) = n 2 is not O(n).
Show that no pair of C and k exists such that n 2 ≤ Cn whenever n > k.
When n > 0, divide both sides of n^2 ≤ Cn by n to get n ≤ C. No matter what C and k are, n ≤ C will not hold for all n with n > k! (There is no bound on the input.)
17
Observe that g(x) = x2 is O(x2 + 2x + 1)
Def: Two functions f(x) and g(x) have the same