To get started, you can import this repo directly in your program:
import "github.com/tlehman/graph"
Then new up a graph and start adding to it:
g := graph.New() // defaults to directed, unweighted
g.addEdge(1, 2)
g.addEdge(1, 3)
g.addEdge(1, 4)
g.addEdge(4, 5)
g.addEdge(5, 2)
g.addEdge(4, 2)
g.addEdge(2, 6)
g.addEdge(6, 5)
fmt.Println(g)
By default the graph prints out in the DOT graph description language
After adding everything to the graph, you can perform:
- Breadth-first search
- Find connected components
- Find minimum spanning trees (only relevant if weighted)
- Compute distances between vertices