Greedy Algorithms - Discrete Mathematics - Lecture Slides, Slides of Discrete Mathematics

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

2012/2013

Uploaded on 04/27/2013

aslesha
aslesha 🇮🇳

4.4

(14)

160 documents

1 / 18

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Discrete Mathematics
CS 2610
September 24, 2008
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Greedy Algorithms - Discrete Mathematics - Lecture Slides and more Slides Discrete Mathematics in PDF only on Docsity!

Discrete Mathematics

CS 2610

September 24, 2008

2

Greedy Algorithms

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

Greedy Algorithms

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

Order of Growth Terminology

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

Complexity of Problems

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

P vs. NP

NP: Solvable problems whose solution can be

checked in polynomial time.

P ⊆ NP

The most famous unproven conjecture in computer

science is that this inclusion is proper.

􀂄􀂄 PNP rather than P = NP

10

Big-O Notation

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

Big-O Notation

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)|

We say f (x) is asymptotically dominated by g (x)

C|g(x)| is an upper bound of f(x).

C and k are called witnesses to the relationship

between f & g.

13

Big-O Notation

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 worksIn many cases, for all x0, 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

Big-O Notation

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

Big-O Notation

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

Big-O Notation

Observe that g(x) = x2 is O(x2 + 2x + 1)

Def: Two functions f(x) and g(x) have the same

order iff g(x) is O(f(x)) and f(x) is O(g(x))