Girvan-Newman

Splits an undirected graph into k communities by removing, one at a time, the edge that the most shortest paths cross.

Time complexity O(E·V·(V+E)), gograph function partition.GirvanNewman.

gograph keeps each undirected edge once per direction and gives each direction half of the edge's betweenness, so the scores shown are half the usual values.

Karate club

The 34 members of a university karate club, numbered 1 to 34 as in the study. Each edge joins two members who also spent time together outside the club's classes and meetings. A dispute between the instructor (1) and an officer (34) split the club in two, and most members sit near the side they joined.

An undirected graph with 34 vertices and 78 edges.

The club split in two after the dispute. Using only who spent time with whom, predict which side each member joined.

Use it in Go

communities, err := partition.GirvanNewman(g, 2)
if err != nil {
	return err
}
for _, c := range communities {
	var members []string
	for _, v := range c.GetAllVertices() {
		members = append(members, v.Label())
	}
	fmt.Println(members)
}

Example graphs

More in Partitioning

  • Maximal cliques: Finds every group of vertices that are all adjacent to each other and can't take one more vertex.
  • Randomized k-cut: Splits an undirected graph into k groups by merging the ends of random edges until k groups are left, and cuts the edges between them.

All algorithms