CSCE 411 Lecture 9

From Notes
Jump to navigation Jump to search
Lecture Slides: 1 2

« previous | Friday, September 14, 2012 | next »


Graphic Matroids

Let be an undirected graph. , and .

Then is a matroid.

  1. is nonempty, and deleting an edge from a forest produces another forest (hereditary)
  2. Let with . then has fewer trees than . Therefore, must contrain a tree , whose vertices are in different trees in the forest . One can add the edge connecting the two different trees to and obtain another forest .

A matroid can be weighted; let represent the weight.

Greedy algorithm

  1. Sort into monotonically decreasing order by weight
  2. for each taken in monotonically decreasing order: if , then add to
def greedy s, f # this is our matroid (s,f)
  a = []
  s.sort! {|v1,v2| v2.weight <=> v1.weight} # sort in decreasing order
  s.each do |x|
    a << x if f.include?(a + [x])
  end
  a
end

Correctness

Seeking a contradiction, suppose that greedy returns , but there exists such that .

Since , we can assume that and are bases.

Let be the smallest index such that .

greedy would've picked at the th step. … So by the exchange property. CONTRADICTION!

Complexity

Let

Suppose that sorting takes

For loop iterates times, but checking whether takes time.

Therefore .

Example

Imagine the triangular graph


Kruskal's Minimum Spanning Tree Algorithm

Let , where is a number that is more than the maximum weight in the graph

  1. sort edges by weight in increasing order (by )
  2. Keep taking edges from the sorted list as long as they do not form a cycle. ( does not contain any graphs with cycles)
  3. Resulting subset of edges will form minimum spanning tree


Dynamic Programming

Similar to Greedy algorithms:

  • Concerned with optimization
  • Optimal solution to problem contains within it optimal solutions to subproblems

However, some of the subproblems overlap


Giving Optimal Change

The "stupid country" version

Sometimes the greedy algorithm doesn't work (e.g. coin values of (1,3,4): greedy algorithm for 6 gives 4,1,1 instead of 3, 3)

Can we design an algorithm htat will give the minimum number of coins as change for any given amount?

Yes, using dynamic programming