diff --git a/graph/prims.cpp b/graph/prims.cpp index a7e8195..de8f5c3 100644 --- a/graph/prims.cpp +++ b/graph/prims.cpp @@ -1,6 +1,7 @@ #include using namespace std; /* + youtube :- https://www.youtube.com/watch?v=HnD676J56ak LOGIC 1.) Maintain two sets i.) First set contains vertices already included in MST @@ -8,7 +9,11 @@ using namespace std; 2.) At every step consider all edges that connects two sets pick the minm weight edge from these edges. - +----------------------------------------------------------------------------------------------------------------- + Use 3 arrays - keys,mstSet,parent + keys -> it contains current vertex se connected vertices ke edge ka weight (Initialized to INT_MAX) + mstSet -> boolean array used to maintain record of vertex included in min span tree + parent -> parent of vertices (It can be used to print min span tree at last) */ int main() @@ -62,4 +67,4 @@ int main() cout << parent[i] << " " << i << "\n"; } return 0; -} \ No newline at end of file +}