From 643b41b5be0992998a9b2971821bcd982df9d290 Mon Sep 17 00:00:00 2001 From: umbridge <44002678+umbridge@users.noreply.github.com> Date: Mon, 5 Oct 2020 08:23:33 +0530 Subject: [PATCH] =?UTF-8?q?Create=20Prim=E2=80=99s=20Minimum=20Spanning=20?= =?UTF-8?q?Tree=20(MST).cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\200\231s Minimum Spanning Tree (MST).cpp" | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 "Algorithms/Graph Algorithms/Prim\342\200\231s Minimum Spanning Tree (MST).cpp" diff --git "a/Algorithms/Graph Algorithms/Prim\342\200\231s Minimum Spanning Tree (MST).cpp" "b/Algorithms/Graph Algorithms/Prim\342\200\231s Minimum Spanning Tree (MST).cpp" new file mode 100644 index 00000000..b011cc06 --- /dev/null +++ "b/Algorithms/Graph Algorithms/Prim\342\200\231s Minimum Spanning Tree (MST).cpp" @@ -0,0 +1,105 @@ +// A C++ program for Prim's Minimum +// Spanning Tree (MST) algorithm. The program is +// for adjacency matrix representation of the graph +#include +using namespace std; + +// Number of vertices in the graph +#define V 5 + +// A utility function to find the vertex with +// minimum key value, from the set of vertices +// not yet included in MST +int minKey(int key[], bool mstSet[]) +{ + // Initialize min value + int min = INT_MAX, min_index; + + for (int v = 0; v < V; v++) + if (mstSet[v] == false && key[v] < min) + min = key[v], min_index = v; + + return min_index; +} + +// A utility function to print the +// constructed MST stored in parent[] +void printMST(int parent[], int graph[V][V]) +{ + cout<<"Edge \tWeight\n"; + for (int i = 1; i < V; i++) + cout<