Simple algorithm & hopcroft karp for bipartite graph


Published on

Published in: Technology
1 Comment
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Simple algorithm & hopcroft karp for bipartite graph

  1. 1. Combinatorial Algorithms(Algorithms in Bipartite Graphs)
  2. 2. IntroductionAlgorithms in unweighted bipartite graphMaximum matchingA simple algorithmHopcroft-Karp algorithmOutline
  3. 3. DefinitionA graph G = (V, E) is bipartite if there exists partitionV = X Y∪ with X Y =∩ ∅ and E X × Y⊆ .Bipartite Graph typesUnweightedWeightedFor every edge e E∈ , there is aweight w(e) .Introduction
  4. 4. Example:There are a set of boys and a set of girls.Each boy only likes girls and each girl only likes boys.A common friend wants to match each boy with a girl such thatthe boy and girl are both happy – but they both will only behappy if the boy likes the girl and the girl likes the boy.Is it possible for every situation?IntroductionWe can use a bipartite graphto model this problem
  5. 5. ProblemTesting bipartitenessMatchingMaximum matching problemIntroduction
  6. 6. Maximum matching
  7. 7. DefinitionMatchingA Matching is a subset M E⊆ such that ∀v V∈ at most oneedge in M is incident upon v– Maximum matching– A Maximum Matching is matching M such that everyothermatching M′ satisfies |M′| ≤ |M|.– Unweighted graph: |M|= the number of edges– Weighted graph: |M|=– Perfect Matching– A matching which matches all vertices of the graphMaximum matching
  8. 8. A Matching A Maximum MatchingNot a MatchingDefinitionWe say that a vertex is matched if it is incident to some edge inM.Otherwise, the vertex is freematchedfree(not perfect)Maximum matching
  9. 9. DefinitionAlternating PathsA path is alternating if its edges alternatebetween M and E − M.Augmenting PathsAn alternating path is augmenting if bothendpoints are freeAlternating TreeA tree rooted at some free vertex v inwhich every path is an alternating path.• Alternating paths( Y1, X2, Y2, X4 )• Augmenting Path(Y1, X2, Y2, X4, Y4, X5)Maximum matching
  10. 10. Property of Augmenting PathsReplacing the M edges by the E − M ones increments size of thematching(Path: Y1, X2, Y2, X4, Y4,X5)Berges Theorem: A matching M is maximum iff ithas no augmenting path (Proof: Lec01 Page 3)Maximum matching
  11. 11. A simple algorithmX2X3X1Y1Y2 Y3 Y4 Maximum matching
  12. 12. A simple algorithmX2X3X1Y1Y2 Y3 Y4 X2X3X1Y1Y2 Y3 Y4 X2X3X1Y1Y2 Y3 Y4 Maximum matching
  13. 13. A simple algorithmX2X3X1Y1Y2 Y3 Y4 X2X3X1Y1Y2 Y3 Y4 X2X3X1Y1Y2 Y3 Y4 X2X3X1Y1Y2 Y3 Y4 Maximum matching
  14. 14. A simple algorithmX2X3X1Y1Y2 Y3 Y4 X2X3X1Y1Y2 Y3 Y4 X2X3X1Y1Y2 Y3 Y4 Maximum matching
  15. 15. A simple algorithm• Commonly search algorithm (BFS, DFS) O(E)• At most V times• Complexity: O(VE)X2X3X1Y1Y2 Y3 Y4 Maximum matching
  16. 16. Hopcroft-Karp AlgorithmAn algorithm to find the maximum matching given abipartite graphGordon
  17. 17. Introduction• The Hopcroft-Karp algorithm was published in1973• It is a matching algorithm that finds amaximum matching in bipartite graphs• The main idea is to augment along a set ofvertex-disjoint shortest augment pathssimulatenously• The complexity is O(√|V||E|)• In this section, some Theorems and Lemmasfrom graph theory will be stated withoutshowing the proof.
  18. 18. Definition• We let the set A B denote the symmetric⊕difference of the set• A B = (A B) – (A B)⊕ ∪ ∩• A maximal set of vertex-disjoint minimumlength augmenting path is defined as follows : It is a set of augmenting path No two path share a same vertex If the minimum length augmenting path is oflength k, then all paths in S are of length k If p is an augmenting path not in S, then pshares a vertex with some path p’ in S
  19. 19. AlgorithmThe algorithm of Hopcroft and Kraft is as follows :Given a graph G = (X Y),E)∪1) Let M = {} ,2) Find S = {P1 , P2 , … Pk}3) While S ≠ {}M = M S⊕Find S4) Output M
  20. 20. Demonstration of algorithm at some stageLet the dark edges represent the edgesin a matching M
  21. 21. Demonstration of algorithm at some stagePink edges represent anaugmenting pathDeleting them
  22. 22. Demonstration of algorithm at some stageAnother augmenting pathNo more paths
  23. 23. Demonstration of algorithm at some stagePink edges represent thepaths in maximal set SM S⊕Note the before and after