Docsity

Greedy Algorithms and Divide and Conquer Algorithms, Slides of Design and Analysis of Algorithms

Partial preview of the text

Download Greedy Algorithms and Divide and Conquer Algorithms and more Slides Design and Analysis of Algorithms in PDF only on Docsity!

Greedy Algorithms and

Divide and Conquer Algorithms

CSE 101: Design and Analysis of Algorithms

Lecture 11

CSE 101: Design and analysis of algorithms

  • Greedy algorithms
    • Reading: Kleinberg and Tardos, sections 4.1, 4.2, and
  • Divide and conquer algorithms
    • Reading: Sections 2.1 and 2.
  • Homework 5 is due Nov 6, 11:59 PM
  • Quiz 2 is Nov 8
    • Graph search and minimum spanning trees

Optimization problems

• In general, when you try to solve a problem, you are trying to find

the best solution from among a large space of possibilities

• Some optimization problems are hard, unless P=NP

• We still need to solve them

• Relax our notion of “solve”: instead of finding a solution GS so that

Value(GS) ≥ Value (OS) for every other solution OS, just guarantee

that GS is approximately optimal with approximation ratio C:

Value(GS) ≥ Value(OS)/C

  • C=1: exact optimal; larger C is worse

Cookies, cannot share same row or column 56 76 69 60 75 51 61 77 74 72 80 58 82 97 94 88 99 92 47 68 59 52 65 40 78 81 79 71 85 62 50 67 73 57 70 46

3. What is an algorithm you could use
to select the best option if you can’t
select 2 cookies from the same row or
column?

maximum weight bipartite perfect matching (MWBPM)

  • B 1 B 2 B 3 B 4 B 5 B
  • A
  • A
  • A
  • A
  • A
  • A - 𝐴 - 𝐴 - 𝐴 - 𝐴 - 𝐴 - 𝐴 - 𝐵 - 𝐵 - 𝐵 - 𝐵 - 𝐵 - 𝐵
    • B 1 B 2 B 3 B 4 B 5 B Maximum weight bipartite perfect matching (MWBPM)
  • A
  • A
  • A
  • A
  • A
  • A - 𝐴 - 𝐴 - 𝐴 - 𝐴 - 𝐴 - 𝐴 - 𝐵 - 𝐵 - 𝐵 - 𝐵 - 𝐵 - 𝐵
    • B 1 B 2 B 3 B 4 B 5 B Maximum weight bipartite perfect matching (MWBPM)
  • A
  • A
  • A
  • A
  • A
  • A - 𝐴 - 𝐴 - 𝐴 - 𝐴 - 𝐴 - 𝐴 - 𝐵 - 𝐵 - 𝐵 - 𝐵 - 𝐵 - 𝐵
    • B 1 B 2 B 3 B 4 B 5 B Maximum weight bipartite perfect matching (MWBPM)
  • A
  • A
  • A
  • A
  • A
  • A - 𝐴 - 𝐴 - 𝐴 - 𝐴 - 𝐴 - 𝐴 - 𝐵 - 𝐵 - 𝐵 - 𝐵 - 𝐵 - 𝐵
    • B 1 B 2 B 3 B 4 B 5 B Maximum weight bipartite perfect matching (MWBPM)
  • A
  • A
  • A
  • A
  • A
  • A - 𝐴 - 𝐴 - 𝐴 - 𝐴 - 𝐴 - 𝐴 - 𝐵 - 𝐵 - 𝐵 - 𝐵 - 𝐵 - 𝐵
    • B 1 B 2 B 3 B 4 B 5 B Maximum weight bipartite perfect matching (MWBPM)
  • A
  • A
  • A
  • A
  • A
  • A - 𝐴 - 𝐴 - 𝐴 - 𝐴 - 𝐴 - 𝐴 - 𝐵 - 𝐵 - 𝐵 - 𝐵 - 𝐵 - 𝐵

Cookies, cannot share same row or column

3. What is an algorithm you could use
to select the best option if you can’t
select 2 cookies from the same row or
column?

56 76 69 60 75 51 61 77 74 72 80 58 82 97 94 88 99 92 47 68 59 52 65 40 78 81 79 71 85 62 50 67 73 57 70 46

Cookies, cannot share same row or column

3. What is an algorithm you could use
to select the best option if you can’t
select 2 cookies from the same row or
column?

56 76 69 60 75 51 61 77 74 72 80 58 82 97 94 88 99 92 47 68 59 52 65 40 78 81 79 71 85 62 50 67 73 57 70 46

Cookies, cannot share same row or column

3. What is an algorithm you could use
to select the best option if you can’t
select 2 cookies from the same row or
column?

56 76 69 60 75 51 61 77 74 72 80 58 82 97 94 88 99 92 47 68 59 52 65 40 78 81 79 71 85 62 50 67 73 57 70 46

Our greedy algorithm is not optimal.
How bad is it?

Immediate benefit vs opportunity costs

  • Immediate benefit: how does the choice we are making now contribute to the objective function?
  • Opportunity costs: how does the choice we are making now restrict future choices?
  • The greedy method (usually) takes the best immediate benefit and ignore opportunity costs
  • The greedy method is optimal: best immediate benefits outweigh opportunity costs

Maximum weight bipartite perfect matching (MWBPM), approximation ratio

  • Theorem: Let GS be the greedy solution to MWBPM. Let OS be any set of
positions that includes at most one per row and one per column. Then,
Total(GS) ≥ ½ Total(OS).
  • How to prove this?
    • If n = 1, then only one choice, so greedy is optimal
    • Let g be the largest entry of the matrix, and say it is in row I and column J. Let
M* be the (n - 1)-by-(n - 1) matrix where we delete row I and column J. OS
has (at most) one element a in row I and one element b in row J. g ≥ a and g ≥
b, so g ≥ ½ (a + b).
  • GS* = GS - {g} is the greedy solution for M* and
OS* = OS - {a, b} is another solution for M*.
So, Total(GS) ≥ ½ Total(OS)
  • Total(GS) = g + Total(GS) ≥ ½ (a + b) + ½ Total(OS) = ½ Total(OS)

Maximum weight bipartite perfect matching (MWBPM), approximation ratio

  • Theorem: Let GS be the greedy solution to MWBPM. Let OS be any set of
positions that includes at most one per row and one per column. Then,
Total(GS) ≥ ½ Total(OS).
  • How to prove it?
    • If n = 1, then only one choice, so greedy is optimal
    • Let g be the largest entry of the matrix, and say it is in row I and column J. Let
M* be the (n - 1)-by-(n - 1) matrix where we delete row I and column J. OS
has (at most) one element a in row I and one element b in row J. g ≥ a and g ≥
b, so g ≥ ½ (a + b).
  • GS* = GS - {g} is the greedy solution for M* and
OS* = OS - {a, b} is another solution for M*.
So, Total(GS) ≥ ½ Total(OS)
  • Total(GS) = g + Total(GS) ≥ ½ (a + b) + ½ Total(OS) = ½ Total(OS)