-
-
Couldn't load subscription status.
- Fork 342
Add Push-Relabel Algorithm in R #260
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds multiple new algorithm implementations to TheAlgorithms/R repository, introducing both graph algorithms and mathematical functions. While the PR title mentions only the Push-Relabel algorithm, it actually contains several new implementations.
- Adds four new graph algorithms: Push-Relabel maximum flow, Edmonds-Karp maximum flow, Hamiltonian path finder, and Boruvka's MST
- Implements Fast Fourier Transform in the mathematics section
- Provides comprehensive documentation for all new algorithms
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| graph_algorithms/push_relabel.r | Implements Push-Relabel algorithm for maximum flow computation |
| graph_algorithms/edmonds_karp.r | Implements Edmonds-Karp algorithm for maximum flow computation |
| graph_algorithms/hamiltonian_path.r | Implements backtracking algorithm to find Hamiltonian paths |
| graph_algorithms/boruvka_mst.r | Implements Boruvka's algorithm for minimum spanning tree |
| mathematics/fast_fourier_transform.r | Implements recursive Cooley-Tukey FFT algorithm |
| documentation/push_relabel.md | Documentation for Push-Relabel algorithm |
| documentation/hamiltonian_path.md | Documentation for Hamiltonian path algorithm |
| documentation/fast_fourier_transform.md | Documentation for FFT algorithm |
| documentation/boruvka_mst.md | Documentation for Boruvka's MST algorithm |
|
|
||
| ## Description | ||
|
|
||
| The implementation builds a Minimum Spanning Tree for an undirected weighted graph using Boruvka's method. The graph is represented by a list with `V` (number of vertices) and `edges` (a data.frame with columns `u`, `v`, `w`). Vertex indices are 1-based to match other algorithms in the repository. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove separate docs
Overview
The
push_relabelfunction computes the maximum flow from a given source to a sink vertex in a directed graph.Unlike the Ford–Fulkerson or Edmonds–Karp methods that rely on augmenting paths, the Push–Relabel algorithm maintains a preflow and adjusts vertex heights to push excess flow efficiently through the network.
This implementation:
It is designed for clarity and educational use, closely matching the behavior of class-based implementations in other languages while being idiomatic to R.
Features
max_flow— total maximum flow valueflow— final flow matrixexcess— excess flow per vertexheight— vertex heights after terminationComplexity
Demonstration
Run the following example in an R session to test the implementation: