From 0e35da7b26c8b3a58cc24233fe4a91ccd78d6440 Mon Sep 17 00:00:00 2001 From: Rajveersinh Gohil <140502093+Rajveer-CSE-27@users.noreply.github.com> Date: Wed, 18 Oct 2023 00:34:20 +0530 Subject: [PATCH 1/3] Update floyd_warshell_algorithm.cpp --- floyd_warshell_algorithm.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/floyd_warshell_algorithm.cpp b/floyd_warshell_algorithm.cpp index c7f951e..f3ae807 100644 --- a/floyd_warshell_algorithm.cpp +++ b/floyd_warshell_algorithm.cpp @@ -1,5 +1,10 @@ /* AABRA KA DABRA.. !! + Here's how the Floyd-Warshall algorithm works: + +Initialization: Create a matrix, often called the "distance matrix" or "adjacency matrix," where each element dist[i][j] represents the shortest distance from vertex i to vertex j. Initially, this matrix is filled with the direct edge weights if there's an edge between vertices i and j, and it's filled with a special value (often infinity) for all other pairs. +Main Loop: The algorithm proceeds by considering all vertices one by one as intermediate vertices. For each vertex k, it checks if the path from vertex i to vertex j through vertex k is shorter than the current known distance from i to j. If it is, then the matrix is updated to reflect this shorter path. +Iteration: The algorithm repeats the Main Loop for all vertices, gradually refining the distance matrix until all shortest paths are found. */ #include "bits/stdc++.h" using namespace std; From cacecff9f9a4a64e33b7390479b5b71633be851e Mon Sep 17 00:00:00 2001 From: Rajveersinh Gohil <140502093+Rajveer-CSE-27@users.noreply.github.com> Date: Wed, 18 Oct 2023 00:37:23 +0530 Subject: [PATCH 2/3] Update kruskal_min_spanning_tree.cpp --- kruskal_min_spanning_tree.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/kruskal_min_spanning_tree.cpp b/kruskal_min_spanning_tree.cpp index 495f138..af74d6b 100644 --- a/kruskal_min_spanning_tree.cpp +++ b/kruskal_min_spanning_tree.cpp @@ -3,13 +3,14 @@ */ /** -A spanning tree is a sub-graph of an undirected connected graph, which includes all the vertices of the graph with a minimum possible number of edges. If a vertex is missed, then it is not a spanning tree. +Sort the Edges: First, sort all the edges of the graph in non-decreasing order of their weights. This can be done using any sorting algorithm, such as quicksort or mergesort. +Create an Empty Tree: Initially, the MST is an empty set of edges. +Iterate Over Edges: Begin iterating through the sorted edges, from the smallest to the largest weight. For each edge, do the following: +a. Check for a Cycle: If adding the current edge to the MST would create a cycle (i.e., if the two endpoints of the edge are already connected in the MST), skip this edge and move on to the next one. You can check for a cycle using techniques like disjoint-set data structures (e.g., Union-Find). +b. Add to MST: If the edge doesn't create a cycle, add it to the MST. This edge is now considered part of the MST. +Repeat: Continue this process until you have added V - 1 edges to the MST, where V is the number of vertices in the graph. This ensures that the resulting tree is indeed a spanning tree, connecting all vertices. +MST is Complete: At the end of the algorithm, you will have constructed a Minimum Spanning Tree that contains all the vertices of the original graph with the minimum possible total weight. -The edges may or may not have weights assigned to them. - -The total number of spanning trees with n vertices that can be created from a complete graph is equal to n(n-2). - -If we have n = 4, the maximum number of possible spanning trees is equal to 44-2 = 16. Thus, 16 spanning trees can be formed from a complete graph with 4 vertices. **/ #include "bits/stdc++.h" using namespace std; From b3ca5eb924b69639ee1a9fc722aaf87cb1bded33 Mon Sep 17 00:00:00 2001 From: Rajveersinh Gohil <140502093+Rajveer-CSE-27@users.noreply.github.com> Date: Wed, 18 Oct 2023 00:38:42 +0530 Subject: [PATCH 3/3] Update kruskal_min_spanning_tree.cpp --- kruskal_min_spanning_tree.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/kruskal_min_spanning_tree.cpp b/kruskal_min_spanning_tree.cpp index af74d6b..88343d9 100644 --- a/kruskal_min_spanning_tree.cpp +++ b/kruskal_min_spanning_tree.cpp @@ -1,7 +1,3 @@ -/* - AABRA KA DABRA.. !! -*/ - /** Sort the Edges: First, sort all the edges of the graph in non-decreasing order of their weights. This can be done using any sorting algorithm, such as quicksort or mergesort. Create an Empty Tree: Initially, the MST is an empty set of edges.