Skip to main content

Posts

Showing posts with the label greedy algorithm

Minimum Spanning Tree using Prim's algorithm [VERY IMPORTANT-Graphs]

CODE:  import java.util.*; import java.lang.*; import java.io.*; class GFG { public static void main (String[] args) { int graph[][] = new int[][] {{0, 2, 0, 6, 0},                                     {2, 0, 3, 8, 5},                                     {0, 3, 0, 0, 7},                                     {6, 8, 0, 0, 9},                                     {0, 5, 7, 9, 0},                                    };     primMST(graph);                       ...