Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for transitive reduction #313

Merged
merged 2 commits into from
May 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ If you are interested, please contact us at zigrazor@gmail.com or contribute to
- [Cycle Detection](#cycle-detection)
- [Bellman-Ford](#bellman-ford)
- [Floyd Warshall](#floyd-warshall)
- [Transitive Reduction](#transitive-reduction)
- [Kruskal Algorithm](#kruskal-algorithm)
- [Borůvka's Algorithm](#borůvkas-algorithm)
- [Graph Slicing based on connectivity](#graph-slicing-based-on-connectivity)
Expand Down Expand Up @@ -432,6 +433,22 @@ We initialize the solution matrix same as the input graph matrix as a first step
1) k is not an intermediate vertex in shortest path from i to j. We keep the value of dist[i][j] as it is.
2) k is an intermediate vertex in shortest path from i to j. We update the value of dist[i][j] as dist[i][k] + dist[k][j] if dist[i][j] > dist[i][k] + dist[k][j]

### Transitive Reduction

[Transitive Reduction](https://en.wikipedia.org/wiki/Transitive_reduction)

This algorithm is used to construct a directed graph with the same reachability and satisfies transitive closure, with as few edges as possible. More concretely, it creates a minimum equivalent graph with as few edges as possible, removing "short-circuit" paths through the graph.

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 80; Actual: 280

Expected: 80; Actual: 280

This is done by iterating through each node-pair, checking to see if two edges exist that leads out of the first node OR out of the last node, removing the node-pair edge if it exists.

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 80; Actual: 184

Expected: 80; Actual: 184

In pseudocode:
foreach x in graph.vertices
foreach y in graph.vertices
foreach z in graph.vertices
delete edge xz if edges xy and yz exist

Our implementation has if gates that do early checking for edges in multiple places, which gives it a slightly faster runtime than the cubic pseudocode here.

Check warning

Code scanning / Markdownlint (reported by Codacy)

Expected: 80; Actual: 157

Expected: 80; Actual: 157

### Kruskal Algorithm

[Kruskal Algorithm](https://en.wikipedia.org/wiki/Kruskal%27s_algorithm) can be used to find the minimum spanning forest of an undirected edge-weighted graph. Time Complexity O(E log E) = O(E log V) where V is number of vertices and E is number of edges in graph. The main speed limitation for this algorithm is sorting the edges.
Expand Down