Hopcroft–Karp algorithm

This is an old revision of this page, as edited by Anks9b (talk | contribs) at 06:27, 24 April 2008. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Introduction

The Hopcroft–Karp algorithm finds maximum cardinality matchings in bipartite graphs in   time, where V is the number of vertices and E is the number of edges of the graph.[1] [2] In the worst case of dense graphs, i.e., when  , the worst-case time estimate is  .

The algorithm is an adaptation of the Edmonds-Karp algorithm for maximum flow, since bipartite matching is equivalent to finding the maximum (integer) flow if the vertices in each partition are considered sources (respectively sinks) of capacity 1. The minimal cut associated with the flow is equivalent to the minimal vertex cover associated with the matching.

Instead of finding just a single augmenting path, the algorithm finds a maximal set of shortest paths in each iteration [3]. As a result only   iterations are needed.


Definition

Consider a graph G(V,E). The following definitions are relative to a matching M in G.

- An alternating path is a path in which the edges would belong alternatively to M and E-M. 
- A free vertex is a vertex which has no incoming edges which belong to M.
- Finally, an augmenting path is an alternating path such that both its end points are free vertices.

Algorithm

The Basic concept that the algorithm relies on is that if we have a matching N of size n, and P is the augmenting path relative to N, then the matching NΔP would have a size of n+1. Thus, since there would be no matching greater in size than the maximum matching, the maximum matching would not have an augmenting path.

Lets name the two sets in which G can be partitioned as U and V. The matching from U to V at any time is represented as the set M. We also maintain a queue(last in first out datastructure) Q in our pseudo code.

Pseudo Code

Initialization:

M = null;


Start :

for u:U

for v:V such that (u,v) belongs to E
 if v is not in M
  { add (u,v) to M
    break; }
end for

end for

for all u:U not in M

if flag_inserted != true
     { insert u in Q
       u.flag_inserted = true; }

end for





References

  1. ^ John E. Hopcroft, Richard M. Karp: An   Algorithm for Maximum Matchings in Bipartite Graphs. SIAM J. Comput. 2(4), 225-231 (1973)
  2. ^ Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein (2001) [1990]. Introduction to Algorithms (2nd edition ed.). MIT Press and McGraw-Hill. pp. 696–697. ISBN 0-262-03293-7. {{cite book}}: |edition= has extra text (help)CS1 maint: multiple names: authors list (link)
  3. ^ Norbert Blum (1999). "A Simplified Realization of the Hopcroft-Karp Approach to Maximum Matching in Nonbipartite Graphs".