Skip to content

Commit 5f2f056

Browse files
authored
Merge pull request #15 from Driolar/master
New section about Hopcroft-Karp algorithm
2 parents 8ee893a + f33027d commit 5f2f056

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

Chapters/Chapter1/chapter1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Graphs are everywhere and there is well-known algorithms to get the best out of them.
44
In this booklet the most common graph algorithms will be explained along with some case studies where these algorithms can be applied. These algorithms are available in the _Pharo AI_ _graph-algorithms_ library available at: [https://github.com/pharo-ai/graph-algorithms](https://github.com/pharo-ai/graph-algorithms).
55

6-
This booklet will describe and implement thess algorithms.
6+
This booklet will describe and implement these algorithms.
77

88
### Paris metro as graph example
99

Chapters/Chapter10/chapter10.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Maximum Flow
22

3+
@cha:maxflow
4+
35
The Maximum Flow problem is about finding the maximum flow through a directed graph, from one node in the graph to another.
46

57
The problem can be used to model a wide variety of real-world situations, such as transportation systems, communication networks, and resource allocation.

Chapters/Chapter9/chapter9.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ Similarly, a **minimum-weight** matching has the smallest sum of weights.
2525

2626
### A greedy algorithm for matching
2727

28-
The algorithm for graph matching implemented in this library is a simple greedy algorithm with time complexity of $O(E * log(V))$.
29-
The class ```AIGraphMatchingAlgorithm``` can be instantiated to find an **approximation** either of the maximum-weight, the minimum-weight or the maximum-cardinality matching.
28+
There is a simple greedy algorithm for graph matching implemented in this library.
29+
The class ```AIGraphMatchingAlgorithm``` can be instantiated to find an **approximation** either of the maximum-weight, the minimum-weight or the maximum-cardinality matching with time complexity of $O(E * log(V))$.
3030

3131
For instance, the pseudocode to greedily find a matching of large weight is the following one:
3232

@@ -53,6 +53,22 @@ To see that the result is not always optimal, consider the two matching versions
5353

5454
The greedy algorithm for maximum-weight would first take weight $1+ \epsilon$ and then stop (top matching in Figure *@epsilon@*), missing the optimal weight sum $1+1$ (bottom matching in Figure *@epsilon@*) .
5555

56+
### Hopcroft-Karp algorithm
57+
58+
The Hopcroft-Karp algorithm computes a matching of maximum-cardinality in an unweighted **bipartite** graph that may contain cycles. The algorithm runs in $O(E * \sqrt{V})$ time.
59+
60+
The Hopcroft-Karp algorithm uses the concept of augmenting paths and a level graph to improve the efficiency of finding the maximum matching. It alternates between two main steps:
61+
62+
1. BFS (Breadth-First Search): This step constructs a level graph and finds the shortest augmenting paths from unmatched vertices in one set of the bipartite graph to unmatched vertices in the other set.
63+
64+
2. DFS (Depth-First Search): This step finds augmenting paths that alternate between unmatched and matched edges, starting from an unmatched vertex in the first set. Once an augmenting path is found, the matching is updated.
65+
66+
These steps are repeated until no more augmenting paths can be found, at which point the algorithm terminates with the maximum matching.
67+
68+
`AIHopcroftKarp>>run` answers the matching cardinality. `AIHopcroftKarp>>matchingEdgeTuples` answers the concrete matching edges (as tuples) after the run.
69+
70+
The Hopcroft-Karp algorithm is basically a special *optimization* of Dinic's algorithm for bipartite unweighted graphs. You find the description of Dinic's algorithm including the augmenting path and level graph concepts in Chapter *@cha:maxflow@*.
71+
5672
### Stable matchings
5773

5874
Maximality and minimality are not the only interesting optimal matching problems.
@@ -92,3 +108,4 @@ Depending on the context, approximation algorithms may be a suitable alternative
92108
From the practical and theoretical points of view, envisaging the special case of bipartite graphs is very common and fructiferous, notably for matching problems.
93109

94110
Both the greedy and the stable matching algorithm presented here are further examples of using a working list until emptied, like discussed for the topological sorting in this book.
111+

pillar.conf

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
{
2-
"base_url" : "",
3-
"attribution" : "Sebastian Jordan Montaño and Stéphane Ducasse",
4-
"keywords" : "project template, Pillar, Pharo, Smalltalk",
5-
"title" : "Pharo Graphs",
6-
"series" : "Square Bracket tutorials",
7-
"htmlWriter" : "html",
8-
"latexWriter" : "miclatex:sbabook",
9-
"site_name" : "Pharo Book",
10-
"tocFile": "index.md",
11-
"bibFile" : "others.bib"
12-
}
1+
{
2+
"base_url" : "",
3+
"attribution" : "Sebastian Jordan Montaño, Stéphane Ducasse and Daniel Lévy",
4+
"keywords" : "project template, Pillar, Pharo, Smalltalk",
5+
"title" : "Pharo Graphs",
6+
"series" : "Square Bracket tutorials",
7+
"htmlWriter" : "html",
8+
"latexWriter" : "miclatex:sbabook",
9+
"site_name" : "Pharo Book",
10+
"tocFile": "index.md",
11+
"bibFile" : "others.bib"
12+
}

0 commit comments

Comments
 (0)