Skip to content

Commit

Permalink
fix: mst typings
Browse files Browse the repository at this point in the history
  • Loading branch information
tolstenko committed Apr 5, 2024
1 parent 9bc0593 commit 620569c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions docs/algorithms/12-mst/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,14 @@ There are many implementations for the Minimum Spanning Tree algorithm, here goe
#include <utility>
using namespace std;

// rename optional<tuple<int, int, int>> to edge
typedef optional<tuple<int, int, int>> Edge;

// rename unordered_map<int, unordered_map<int, int>> to Graph
typedef unordered_map<int, unordered_map<int, int>> Graph;

// source, destination, weight
optional<tuple<int, int, int>> findMinEdge(const unordered_map<int, unordered_map<int, int>>& graph, const unordered_map<int, unordered_map<int, int>>& mst){
Edge findMinEdge(const Graph& graph, const Graph& mst){
if(graph.empty())
return nullopt;
if(mst.empty()){
Expand Down Expand Up @@ -622,8 +628,8 @@ optional<tuple<int, int, int>> findMinEdge(const unordered_map<int, unordered_ma

// returns the accumulated weight of the minimum spanning tree
// the graph is represented as [source, destination] -> weight
int MSP(unordered_map<int, unordered_map<int, int>> graph){
unordered_map<int, unordered_map<int, int>> mst;
int MSP(const Graph& graph){
Graph mst;
int accumulatedWeight = 0;
while(true){
auto edge = findMinEdge(graph, mst);
Expand Down

0 comments on commit 620569c

Please sign in to comment.