From 1310b7f65dd8f7a049e0c93abc78ed16cbc7f670 Mon Sep 17 00:00:00 2001 From: tanya-0708 Date: Sun, 4 Oct 2020 19:31:34 +0530 Subject: [PATCH] Added prim's algo --- Prims Algo.txt | 104 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 Prims Algo.txt diff --git a/Prims Algo.txt b/Prims Algo.txt new file mode 100644 index 0000000..4257d81 --- /dev/null +++ b/Prims Algo.txt @@ -0,0 +1,104 @@ + + +#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<