CSCE 411 Lecture 7

From Notes
Jump to navigation Jump to search
Lecture Slides

« previous | Monday, September 10, 2012 | next »


Greedy Algorithms and Matroids

Useful for solving optimization problems

  1. Cast optimization problem as one in which we make a choice and are left with one subproblem to solve
  2. Prove that there is always an optimal solution to the original problem that makes the greedy choice, so that the greedy choice is always safe
  3. Demonstrate that, having made the greedy choice, what remains is a subproblem with the property that if we combine an optimal solution to the subproblem with the greedy choice that we have made, we arrive at an optimal solution to the original problem.

geedy-choice property: globally optimal solution that can be arrived at by making the optimal (hence greedy) choice at each step of the algorithm.

Easy to design, but hard to show correctness.


Giving Change

Suppose we have types of coins with values .

Given an amount , a positive integer, the following algorithm tries to give change for :

num_coins = Array.new(n, 0)
(1..n).each do |i|
    while C >= v[i]
        C -= v[i]
        num_coins[i] += 1
    end
end

# C == (1..n).map{|i| num_coins[i]*v[i]}.inject(:+)

Is this solution optimal? Does it give the least number of coins?

Suppose .

Optimal solution must satisfy

  1. if , replace two 1's with a 2
  2. , otherwise we would use a 5
  3. If , then or solution would violate (2)

Q.E.D. The optimal solution is the greedy solution.


HOWEVER

If , our algorithm would choose , which is not optimal.

In order for greedy algorithms to work, the optimal solution to a larger problem must have an optimal solution to its subproblems. (optimal substructure [1])

Matroids

Combinatorial structure

Let be a finite set, and be a nonempty family of subsets of , i.e.

We call a matroid iff

  1. (hereditary)
  2. (exchange property)

Example 1: Matric Matroids

Let be a matrix Let be the set of rows of and

Claim: is a matroid.


isn't empty (it contains every row of )

  1. If is a set of linearly independent rows of , then any subset of is linearly independent, so is hereditary.
  2. If are sets of linearly independent rows of , then dim span < dim span . Choose a row in that is not contained in span . Then is a linearly independent subset of rows of , so satisfies the exchange property.

Graphs

A set of Vertices/nodes and Edges

An induced graph is a graph that contains a subset of edges of an original graph .


Footnotes

  1. A problem exhibits optimal substructure iff an optimal solution to the problem contains within it optimal solutions to subproblems