diff --git a/src/main/java/com/thealgorithms/graph/PrismAlgorithm.java b/src/main/java/com/thealgorithms/graph/PrismAlgorithm.java new file mode 100644 index 000000000000..584dfd6ee965 --- /dev/null +++ b/src/main/java/com/thealgorithms/graph/PrismAlgorithm.java @@ -0,0 +1,59 @@ +package com.thealgorithms.graph; + +import java.util.*; + + + +/** + * This class provides a method to compute the Minimum Spanning Tree (MST) + * weight using Prim's Algorithm without any custom helper class. + */ +public class PrismAlgorithm { + + /** + * Computes the total weight of the Minimum Spanning Tree (MST) + * for a given undirected, weighted graph using Prim's Algorithm. + * + * @param V Number of vertices in the graph. + * @param adj Adjacency list representation of the graph. + * Each entry: {adjacentNode, edgeWeight}. + * @return The sum of the edge weights in the MST. + * + *
Time Complexity: O(E log V)
+ *Space Complexity: O(V + E)
+ */ + static int spanningTree(int V, ArrayList