Hopcroft–Karp algorithm

Hopcroft–Karp algorithm

The Hopcroft–Karp algorithm finds maximum cardinality matchings in bipartite graphs in O(sqrt{V} E) time, where "V" is the number of vertices and "E" is the number of edges of the graph. [John E. Hopcroft, Richard M. Karp: "An n^{5/2} Algorithm for Maximum Matchings in Bipartite Graphs." SIAM J. Comput. 2(4), 225-231 (1973)] Introduction to Algorithms|2|chapter=26.5: The relabel-to-front algorithm|pages=pp. 696–697] In the worst case of dense graphs, i.e., when E=O(V^2), the worst-case time estimate is O(V^{5/2}).

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 [cite web|author=Norbert Blum|title=A Simplified Realization of the Hopcroft-Karp Approach to Maximum Matching in Nonbipartite Graphs|url=http://citeseer.ist.psu.edu/258961.html|date=1999] . As a result only O(sqrt{V}) 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 P is an alternating path such that both its end points are free vertices.
* Symmetric difference M'=Moplus P has all edges of M and P except shared edges Mcap P

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 Noplus 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.

The algorithm is run in phases. Each phase consists of:
* A BFS is run from free U vertices. This BFS stops at layer "k" where one or more free V vertices are reached. Collect "all" free V vertices at layer "k" and put them in the set F. A vertex "v" is put in F iff vin V and "v" ends a shortest augmenting path.
* Find a maximal set of "vertex disjoint" augmenting paths of length "k". This is set is computed by DFS from F (computed by BFS) to free U vertices. Every one of this paths is used to enlarge M.

"Pseudo Code" for all qin U cup V q.matching= null; end for while (true) // Find all potential beginnings of shortest augmenting paths B := empty; for all u:U s.t. (u.matching = null) insert u in B; end for // Find all endings of shortest augmenting paths F := Find_Augmenting_Path_Endings(B); if (F is empty) M:= empty; for all u:U s.t. (u.matching ≠ null) insert (u, u.matching) in M; // insert edge end for return M; end if Augment_Paths(F); end while

// Perform BFS starting with vertices of B. // Return: a list of free vertices which potentially // end the shortest vertex-disjoint augmenting paths. // Side effect: For any vertex v.layer has the index of // the BFS layer to reach this vertex (or -1) // B: potential beginning of augmenting paths Find_Augmenting_Path_Endings(B): Q := B; // F: The set of free endings (the other side of augmenting paths) F := empty; for all qin U cup V q.layer:=-1; end for // The potential beginnings of augmenting paths are at layer 0. for all b:B b.layer:=0; end for while (Q is not empty) Q' := empty; for all q: Q for all (q,p):E s.t. (p.layer = -1) p.layer:= q.layer+1; if (p.matching = null) insert p in F; // Collect the free vertex, continue BFS else insert p in Q'; end if end for end for if (F is not empty) return F; // Free vertices found, stop at this layer. end if Q:= empty; for all q:Q' // By construction, q matched. p:= q.matching; p.layer:= q.layer+1; insert p in Q; end for end while return empty;

Augment_Paths(F): for all qin U cup V q.visited= false; end for for all q:F P:=Get_Augmenting_Path(q); // Make sure q ends a "vertex-disjoint" augmenting path if (P is not empty) // Perform M := Moplus P odd := true; for all (t,q):P if (odd) // Make (t,q) match (first, third, ... edges) p.matching := q; q.matching := t; odd := false; else // t.matching has already been updated by the "odd" condition q.matching := null; // This is not strictly required odd := true; end if end for end if end for

// DFS from p, avoiding previously visited vertices. // Start at the last layer of BFS, and go backwards // to layer 0. Get_Augmenting_Path(p): if (p.visited) return empty; end if p.visited:= true; if (p.layer = 0) // layer 0 has free vertices. return (p); end if // Consider only edges going one layer backwards. for all (q,p):E such that p.layer+1=q.layer P= Get_Augmenting_Path(q); if (P not empty) return (q, P); // Prepend q to the path found so far. end if end for // Could not find a vertex-disjoint augmenting path ending with p. return empty;

References


Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • Dinic's algorithm — is a strongly polynomial algorithm for computing the maximum flow in a flow network, conceived in 1970 by Israeli (formerly Soviet) computer scientist Yefim Dinitz. The algorithm runs in O(V2E) time and is similar to the Edmonds–Karp algorithm,… …   Wikipedia

  • Matching (graph theory) — In the mathematical discipline of graph theory, a matching or independent edge set in a graph is a set of edges without common vertices. It may also be an entire graph consisting of edges without common vertices. Covering packing dualities… …   Wikipedia

  • Permanent is sharp-P-complete — The correct title of this article is Permanent is #P complete. The substitution or omission of the # sign is because of technical restrictions. In a 1979 paper Leslie Valiant proved[1] that the problem of computing the permanent of a matrix is #P …   Wikipedia

  • Pidgin code — In computer programming, pidgin code is a mixture of several programming languages in the same program, or pseudocode that is a mixture of a programming language with natural language descriptions. Hence the name: the mixture is a programming… …   Wikipedia

  • List of mathematics articles (H) — NOTOC H H cobordism H derivative H index H infinity methods in control theory H relation H space H theorem H tree Haag s theorem Haagerup property Haaland equation Haar measure Haar wavelet Haboush s theorem Hackenbush Hadamard code Hadamard… …   Wikipedia

  • Network controllability — Controlling a simple network. Network Controllability concerns the controllability a network. Controllability describes our ability to guide a dynamical system from any initial state to any desired final state in finite time, with a suitable… …   Wikipedia

  • Matching (Graphentheorie) — Die Theorie um das Finden von Matchings in Graphen ist in der diskreten Mathematik ein umfangreiches Teilgebiet, das in die Graphentheorie eingeordnet wird. Folgende Situation wird dabei betrachtet: Gegeben eine Menge von Dingen und zu diesen… …   Deutsch Wikipedia

  • Computational complexity theory — is a branch of the theory of computation in theoretical computer science and mathematics that focuses on classifying computational problems according to their inherent difficulty, and relating those classes to each other. In this context, a… …   Wikipedia

  • NP-complete — Euler diagram for P, NP, NP complete, and NP hard set of problems In computational complexity theory, the complexity class NP complete (abbreviated NP C or NPC) is a class of decision problems. A decision problem L is NP complete if it is in the… …   Wikipedia

  • Michael O. Rabin — Michael Oser Rabin Born September 1, 1931 (1931 09 01) (age 80) Breslau …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”