Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the Hopcroft-Karp algorithm work?

I am currently working on a project to pictorially explain the Hopcroft-Karp algorithm.

I am using the pseudo-code from the Wikipedia article.

I have also seen this algorithm implemented on Stack Overflow in Python

This would do fantastically if only I didn't have to understand the algorithm completely to use it.

My questions are as follows: What is the meaning of the Dist[] array in the pseudo-code, and how is the layering of the graph done in the Breadth-First-Search. I have a grasp on the workings of the DFS.

Thanks in advance.

like image 320
Schisis Avatar asked Jun 16 '11 02:06

Schisis


People also ask

What is augmenting path how it is computed with Edmonds Blossom algorithm?

That is, when the algorithm come across an edge (v, w) that connects two trees, it takes the alternating path from the the root of v to v, then adds the new edge from (v, w), then adds the alternating path from w to the root of w. The algorithm then returns this augmenting path.

What is matching algorithm in graph theory?

Matching algorithms are algorithms used to solve graph matching problems in graph theory. A matching problem arises when a set of edges must be drawn that do not share any vertices. Graph matching problems are very common in daily activities.

What are the matching and augmenting paths?

An alternating path with respect to a matching M is a path in which edges alternate between those in M and those not in M . An augmenting path is an alternating path that starts and ends with a free vertex.


1 Answers

The standard BFS creates layers such that nodes in successive layers are at a distance of exactly 1 apart (i.e. there is a path of length 1 between the nodes of successive layers).

for v in G1
    if Pair[v] == NIL
       Dist[v] = 0
       Enqueue(Q,v)
   else
       Dist[v] = INF

So that code initializes the first layer of the BFS tree, setting all "free nodes" v (i.e. Pair[v] == NIL) to be at distance 0.

while Empty(Q) == false
   v = Dequeue(Q)
   for each u in Adj[v]
        if Dist[ Pair[u] ] == INF
             Dist[ Pair[u] ] = Dist[v] + 1
             Enqueue(Q,Pair[u])

and this code continues on building the BFS tree layer by layer, for nodes u that are neighbors of v (at distance exactly one).

Dist[] is just a way to manage the distances from nodes to the initial layer of the BFS

like image 120
kaveman Avatar answered Sep 19 '22 15:09

kaveman