-
-
Notifications
You must be signed in to change notification settings - Fork 342
Prim mst #267
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?
Prim mst #267
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 pull request adds implementations of Prim's Minimum Spanning Tree (MST) algorithm along with extensive supporting algorithm implementations across multiple categories (graph algorithms, dynamic programming, mathematics, and machine learning). The PR also includes documentation files for various machine learning techniques.
Key changes:
- Implements Prim's MST algorithm for finding minimum spanning trees in weighted graphs
- Adds complementary graph algorithms (Kruskal's MST, Dijkstra, Bellman-Ford, DFS, BFS, topological sort, Hamiltonian cycle, bridge detection, Floyd-Warshall)
- Includes dynamic programming implementations (knapsack, LCS, LIS, coin change, subset sum, matrix chain multiplication, minimum path sum)
- Adds mathematics utilities (Catalan numbers, bisection method, Armstrong numbers, amicable numbers, Euclidean distance)
- Provides machine learning implementations (gradient boosting, bridge detection)
Reviewed Changes
Copilot reviewed 138 out of 212 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| graph_algorithms/prim_mst.r | Implements Prim's MST algorithm with adjacency list representation |
| graph_algorithms/kruskal_mst.r | Implements Kruskal's MST algorithm with union-find |
| graph_algorithms/dijkstra_shortest_path.r | Shortest path algorithm with priority queue |
| graph_algorithms/bellman_ford_shortest_path.r | Shortest path with negative edge support |
| graph_algorithms/floyd_warshall.r | All-pairs shortest paths using R6 class |
| graph_algorithms/depth_first_search.r | DFS with recursive and iterative implementations |
| graph_algorithms/breadth_first_search.r | BFS with path finding utilities |
| graph_algorithms/topological_sort.r | Kahn's algorithm for DAG ordering |
| graph_algorithms/hamilitonian_cycle.r | Backtracking-based cycle detection |
| graph_algorithms/bridge_detector.r | Tarjan's algorithm for critical edge detection |
| kruskal_mst.r | Duplicate Kruskal implementation in root directory |
| dynamic_programming/* | Multiple DP algorithm implementations |
| mathematics/* | Various mathematical algorithms and utilities |
| machine_learning/gradient_boosting.r | Gradient boosting regressor with R6 classes |
| machine_learning/README.md | Machine learning resources and tutorials |
| documentation/* | Generated documentation files for ML algorithms |
| @@ -0,0 +1,124 @@ | |||
| # Kruskal's Minimum Spanning Tree (MST) Algorithm | |||
Copilot
AI
Oct 20, 2025
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.
This file duplicates the implementation found in graph_algorithms/kruskal_mst.r. According to repository guidelines, algorithms should be placed in the appropriate category directory. Remove this root-level file and keep only the version in graph_algorithms/ to maintain proper organization.
| @@ -0,0 +1,102 @@ | |||
| # Hamiltonian Cycle Detection (Backtracking) | |||
Copilot
AI
Oct 20, 2025
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.
Corrected spelling of 'hamilitonian' to 'hamiltonian' in filename.
| @@ -0,0 +1,155 @@ | |||
| # 0/1 Knapsack Problem (Dynamic Programming) | |||
Copilot
AI
Oct 20, 2025
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.
The file path 0/1_knapsack_problem.r contains characters that may cause issues on some filesystems and version control systems. The filename starts with a digit and contains a slash character in the directory name. Consider renaming to dynamic_programming/knapsack_01.r or dynamic_programming/zero_one_knapsack.r to avoid potential compatibility issues.
| @@ -0,0 +1,194 @@ | |||
| # 0/1 Knapsack Problem (Dynamic Programming) | |||
Copilot
AI
Oct 20, 2025
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.
This file duplicates the knapsack implementation at dynamic_programming/0/1_knapsack_problem.r with only minor differences. The nested directory structure 0/0/ also creates filesystem compatibility issues. Remove this duplicate file and consolidate into a single knapsack implementation in the dynamic_programming/ directory.
| cat("Remaining budget:", budget - sum(selected_projects), "\n") | ||
| } else { | ||
| # Find closest possible sum (≤ budget) in a single pass | ||
| closest_sum <- max_subset_sum_leq(project_costs, budget) |
Copilot
AI
Oct 20, 2025
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.
The function max_subset_sum_leq is called but never defined in this file. This will cause a runtime error. Either implement this helper function or remove this line from the example.
| } | ||
|
|
||
| # Count feature usage and gain in splits | ||
| n_features <- ncol(X) # Assumes X from last fit |
Copilot
AI
Oct 20, 2025
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.
The variable X is not in scope within the get_feature_importance method. This will cause an error when the method is called. Store n_features as a class field during the fit method, or pass it as a parameter to get_feature_importance.
|
You have changed 212 files, check your changes |
The Prim algorithm finds the MST of a connected, undirected, weighted graph.
It starts from a source vertex and repeatedly adds the smallest-weight edge connecting the MST to a new vertex until all vertices are included.
Time Complexity: O(V²) with adjacency list (or O(E log V) with a priority queue)
Space Complexity: O(V)
Input: Graph as an adjacency list and a source vertex index
Output: MST edges and total weight.