Presentation is loading. Please wait.

Presentation is loading. Please wait.

Midterm < 20 1 20-29 0 30-39 4 40-49 5 50-59 9 60-69 7  70 3.

Similar presentations


Presentation on theme: "Midterm < 20 1 20-29 0 30-39 4 40-49 5 50-59 9 60-69 7  70 3."— Presentation transcript:

1 Midterm < 20 1 20-29 0 30-39 4 40-49 5 50-59 9 60-69 7  70 3

2 Matchings matching M = subgraph with vertices of degree  1

3 Matchings = unmatched vertex (vertex not in M) matching M = subgraph with vertices of degree  1

4 Matchings matching M = subgraph with vertices of degree  1 = unmatched vertex (vertex not in M) perfect matching = matching with no unmatched vertices (perfect world – everybody has a buddy)

5 Perfect matching

6 Maximal / maximum maximal = no edge can be added to M to make a bigger matching maximum = there is no matching with more edges maximal, NOT maximum maximum  maximal

7 Augmenting path path connecting two unmatched vertices with alternating non-matching and matching edges If there exists augmenting path then the matching is NOT maximum.

8 Augmenting path path connecting two unmatched vertices with alternating non-matching and matching edges

9 Augmenting path path connecting two unmatched vertices with alternating non-matching and matching edges Lucky ?

10 Augmenting path Lucky ? NO Theorem: If matching M is not maximum then there exists an augmenting path.

11 Augmenting path Theorem: If the matching M is not maximum then there exists an augmenting path. M = matching, not maximum B = bigger matching

12 Proof M = matching, not maximum B = bigger matching MBMB

13 Proof M = matching, not maximum B = bigger matching MBMB

14 Proof M = matching, not maximum B = bigger matching MBMB

15 Proof M = matching, not maximum B = bigger matching MBMB vertices of degree 0,1,2  paths and cycles no odd cycles must have a path with more edges from B than from M  augmenting path

16 How to find maximum matching? M  repeat find augmenting path P M  M  P until no augmenting path

17 Augmenting path in bipartite graphs augmenting path has odd length  endpoints on different sides call the one on the left start non matching edges matching edges

18 Augmenting path in bipartite graphs augmenting path has odd length  endpoints on different sides call the one on the left start non matching edges matching edges

19 Augmenting path in bipartite graphs augmenting path has odd length  endpoints on different sides call the one on the left start non matching edges matching edges Theorem: augmenting path exists  there is a path from unmatched vertex on the left to an unmatched vertex on the right

20 Augmenting path in bipartite graphs augmenting path has odd length  endpoints on different sides call the one on the left start non matching edges matching edges Theorem: augmenting path exists  there is a path from the blue vertex on the left to the blue vertex on the right

21 Augmenting path in bipartite graphs Finding augmenting path (or checking none exists) one BFS (or DFS) computation TIME = O(E) Finding max-matching O( VE ) M  repeat find augmenting path P M  M  P until no augmenting path

22 Maximum-weight matchings 10 5 5 5 5 5 5

23 Maximum-weight matchings 10 5 5 5 5 5 5 weight = 30 maximum-weight matching doesn’t have to be maximum cardinality !!!

24 Augmenting path path connecting two unmatched vertices with alternating non-matching and matching edges + -++-   w e >  w f e  P  M C f  P  M must gain by the swap:

25 Augmenting greedily Assume M = matching of the maximum-weight among matchings with k edges P = augmenting path with maximum gain Then M  P = matching of the maximum weight among matchings with k+1 edges THEOREM:

26 Augmenting greedily Assume M = matching of the maximum-weight among matchings with k edges P = augmenting path with maximum gain Then M  P = matching of the maximum weight among matchings with k+1 edges Proof: B = max-weight with k+1 edges M  B

27 Augmenting greedily Assume M = matching of the maximum-weight among matchings with k edges P = augmenting path with maximum gain Then M  P = matching of the maximum weight among matchings with k+1 edges Proof: B = max-weight with k+1 edges M  B gain = 0

28 Augmenting greedily Assume M = matching of the maximum-weight among matchings with k edges P = augmenting path with maximum gain Then M  P = matching of the maximum weight among matchings with k+1 edges Proof: B = max-weight with k+1 edges M  B gain = 0

29 Augmenting greedily Assume M = matching of the maximum-weight among matchings with k edges P = augmenting path with maximum gain Then M  P = matching of the maximum weight among matchings with k+1 edges Proof: B = max-weight with k+1 edges M  B gain = 0

30 Augmenting greedily Assume M = matching of the maximum-weight among matchings with k edges P = augmenting path with maximum gain Then M  P = matching of the maximum weight among matchings with k+1 edges Proof: B = max-weight with k+1 edges M  B gain = wt(B) – wt(M)

31 How to find maximum-weight matching? M  repeat find augmenting path P with maximum gain M  M  P until no augmenting path only need O(V) iterations

32 How to find augmenting path with the maximum gain? + -

33 SHORTEST PATH PROBLEM How to find augmenting path with the maximum gain? + -

34 NEGATIVE CYCLE? How to find augmenting path with the maximum gain? + -

35 NEGATIVE CYCLE? How to find augmenting path with the maximum gain? + - impossible – would contradict maximality (among matchings of cardinality k)

36 How to find augmenting path with the maximum gain? no negative cycles  can use Bellman-Ford to find the shortest path (and hence get augmenting path with the maximum gain)

37 Putting it all together M  repeat find augmenting path P with maximum gain M  M  P until no augmenting path only need O(V) iterations O(VE) time per iteration (Bellman-Ford) O(V 2 E) time total

38 Putting it all together M  repeat find augmenting path P with maximum gain M  M  P until no augmenting path only need O(V) iterations O(Vlog V + E) time per iteration (Dijkstra) O(V 2 log V + VE) time total

39 Back to midterm

40

41

42 Linear ordering of vertices of a directed acyclic graph such that no edges point backward.

43 2 log n = n n 1/log n = (2 log n ) 1/log n = 2 (log n)/log n = 2 n 2/log n = (2 log n ) 2/log n = 2 2(log n)/log n = 4 1 n 1 + 1/log n = n. n 1/log n = 2n n n 2 binomial(n,2)=n(n-1)/2

44 Mergesort reduces an instance of size n to 2 instances of size n/2 and the reduction takes time  (n).

45 Assume that all degrees  2. Then 2 |E| =  deg(v)   2 = 2 n vVvVvVvV Hence there is a vertex of degree  1. There cannot be a vertex of degree 0, since G is connected and |V|  2. Hence there is a vertex of degree = 1.

46 max { E[ i ], O[ j ] + 1} max { O[ i ], E[ j ] + 1}

47 max { B[i-1], B[i-2] + a i }

48 for i from 1 to n do for j from 1 to n do A[i,j]  (A[i,j] + (i+j)) mod 2 M 1  largest all-ones square M 2  largest all-zeros square return max (M 1, M 2 )

49 for i from 1 to n do for j from 1 to n do M[i,j]  1 if i>1 and j>1 then if (A[i,j]=A[i-1,j-1]) and (A[i,j]  A[i-1,j]) and (A[i,j]  A[i,j-1]) M[i,j]  1+min(M[i-1,j],M[i,j-1],M[i-1,j-1]) return max M[i,j] i,j  {1,...,n}

50 Extract-Min(H) min  H[1] H[1]  H[n] n  n-1 Heapify(H,1) return min H = heap n = size of the heap

51 input: weighted, undirected graph G (given by adjacency list) output: minimum-cost spanning tree of G (cost of a tree is the sum of the weights of its edges)


Download ppt "Midterm < 20 1 20-29 0 30-39 4 40-49 5 50-59 9 60-69 7  70 3."

Similar presentations


Ads by Google