Title: Midterm
1Midterm
0 30-39 4 40-49
5 50-59 9 60-69 7 ?
70 3
2Matchings
matching M subgraph with
vertices of degree 1
3Matchings
unmatched vertex (vertex not in M)
matching M subgraph with
vertices of degree 1
4Matchings
unmatched vertex (vertex not in M)
matching M subgraph with
vertices of degree 1
perfect matching matching with no unmatched
vertices
(perfect world everybody has a buddy)
5Perfect matching
6Maximal / maximum
maximal no edge can be added to M to make a
bigger matching maximum there
is no matching with more edges
maximum ? maximal
maximal, NOT maximum
7Augmenting path
path connecting two unmatched vertices with
alternating non-matching and matching edges
If there exists augmenting path then the
matching is NOT maximum.
8Augmenting path
path connecting two unmatched vertices with
alternating non-matching and matching edges
9Augmenting path
path connecting two unmatched vertices with
alternating non-matching and matching edges
Lucky ?
10Augmenting path
Lucky ?
NO
Theorem If matching M is not maximum then
there exists an augmenting path.
11Augmenting path
Theorem If the matching M is not maximum then
there exists an augmenting path.
M matching, not maximum B bigger matching
12Proof
M matching, not maximum B bigger matching
M?B
13Proof
M matching, not maximum B bigger matching
M?B
14Proof
M matching, not maximum B bigger matching
M?B
15Proof
M matching, not maximum B bigger matching
M?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
16How to find maximum matching?
M?0 repeat find augmenting path P M ?
M?P until no augmenting path
17Augmenting 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
18Augmenting 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
19Augmenting 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
20Augmenting 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
21Augmenting path in bipartite graphs
Finding augmenting path (or checking none
exists) one BFS (or DFS) computation TIME O(E)
M?0 repeat find augmenting path P M ?
M?P until no augmenting path
Finding max-matching O( VE )
22Maximum-weight matchings
5
5
10
10
5
5
5
5
10
23Maximum-weight matchings
5
5
10
10
5
weight 30
5
5
5
10
maximum-weight matching doesnt have to be
maximum cardinality !!!
24Augmenting path
-
-
path connecting two unmatched vertices with
alternating non-matching and matching edges
must gain by the swap
? we ? wf
f? P?M
e? P?MC
25Augmenting greedily
THEOREM
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 k1
edges
26Augmenting 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 k1
edges
Proof B max-weight with k1 edges M?B
27Augmenting 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 k1
edges
gain 0
Proof B max-weight with k1 edges M?B
28Augmenting 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 k1
edges
gain 0
Proof B max-weight with k1 edges M?B
29Augmenting 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 k1
edges
gain 0
Proof B max-weight with k1 edges M?B
30Augmenting 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 k1
edges
Proof B max-weight with k1 edges M?B
gain wt(B) wt(M)
31How to find maximum-weight matching?
M?0 repeat find augmenting path P with
maximum gain M ? M?P until no augmenting path
only need O(V) iterations
32How to find augmenting path with the maximum gain?
-
33How to find augmenting path with the maximum gain?
-
SHORTEST PATH PROBLEM
34How to find augmenting path with the maximum gain?
NEGATIVE CYCLE?
-
35How to find augmenting path with the maximum gain?
NEGATIVE CYCLE?
impossible would contradict maximality (among
matchings of cardinality k)
-
36How 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)
37Putting it all together
M?0 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(V2 E) time total
38Putting it all together
M?0 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(V2log V VE) time total
39Back to midterm
40(No Transcript)
41(No Transcript)
42Linear ordering of vertices of a directed
acyclic graph such that no edges point backward.
432log n n
1
n1/log n (2log n )1/log n 2 (log n)/log n 2
n2/log n (2log n )2/log n 2 2(log n)/log n 4
n
n1 1/log n n . n1/log n 2n
n2 binomial(n,2)n(n-1)/2
44Mergesort reduces an instance of size n to 2
instances of size n/2 and the reduction takes
time ?(n).
45Assume that all degrees ? 2. Then 2 E ?
deg(v) ? ? 2 2 n
v?V
v?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.
46max E i , O j 1
max O i , E j 1
47max Bi-1, Bi-2 ai
48for i from 1 to n do for j from 1 to n do
Ai,j ? (Ai,j (ij)) mod 2 M1 ? largest
all-ones square M2 ? largest all-zeros
square return max (M1, M2)
49for i from 1 to n do for j from 1 to n do
Mi,j ? 1 if i1 and j1 then
if (Ai,jAi-1,j-1) and (Ai,j? Ai-1,j)
and (Ai,j? Ai,j-1)
Mi,j? 1min(Mi-1,j,Mi,j-1,Mi-1,j-1)
return max Mi,j
i,j? 1,...,n
50H heap n size of the heap
Extract-Min(H) min ? H1 H1 ? Hn n
? n-1 Heapify(H,1) return min
51input 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)