Skip to content

Instantly share code, notes, and snippets.

@soundsmitten
soundsmitten / prim.java
Created December 12, 2012 22:39
Java- Prim's minimum spanning tree
// From Wikipedia: Prim's algorithm is a greedy algorithm that
// finds a minimum spanning tree for a connected weighted undirected graph.
// This means it finds a subset of the edges that forms a tree that
// includes every vertex, where the total weight of all the edges in the tree is minimized.
void Prim(int n, int[][] W, int[] nearest)
{
int[]distance
for( i = 1; i<=n; i++)
{
@soundsmitten
soundsmitten / mColor.java
Created December 12, 2012 22:34
Java M-Coloring Graph algorithm.
// Wikipedia: a way of coloring the vertices of a graph such that no two
// adjacent vertices share the same color; this is called a vertex coloring.
// Similarly, an edge coloring assigns a color to each edge so that no two adjacent
// edges share the same color, and a face coloring of a planar graph assigns a color to
// each face or region so that no two faces that share a boundary have the same color.
// In NP-complete
boolean mcolor(int i, int m, int n, bool [][] W, int [] vcolor, int n)
{
// i: last colored vertex
// m: number of colors