CSCE 411 Lecture 7
« previous | Monday, September 10, 2012 | next »
Greedy Algorithms and Matroids
Useful for solving optimization problems
- Cast optimization problem as one in which we make a choice and are left with one subproblem to solve
- 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
- 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
- if , replace two 1's with a 2
- , otherwise we would use a 5
- 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
- (hereditary)
- (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 )
- If is a set of linearly independent rows of , then any subset of is linearly independent, so is hereditary.
- If Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle A,B} are sets of linearly independent rows of Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle M} , then dim span Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle A} < dim span Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle B} . Choose a row Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle x} in Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle B} that is not contained in span Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle A} . Then Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle A \cup \{x\}} is a linearly independent subset of rows of Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle M} , so Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle F} satisfies the exchange property.
Graphs
A set of Vertices/nodes Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle V} and Edges Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle E \subseteq \{e \mid e \subset V \wedge |e| = 2 \}}
An induced graph is a graph Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle (V,E')} that contains a subset of edges of an original graph Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle (V, E)} .
Footnotes
- ↑ A problem exhibits optimal substructure iff an optimal solution to the problem contains within it optimal solutions to subproblems