Transitive reduction

Drops every edge that a longer path already implies. Each vertex still reaches the same vertices.

Time complexity O(V(V+E)), gograph function path.TransitiveReduction.

Course prerequisites

Fourteen courses of a computer science degree. Each edge points from a course to a course that requires it.

A directed graph with 14 vertices and 18 edges.

Which prerequisites can the course list leave out, because they already come through another course?

Use it in Go

reduced, err := path.TransitiveReduction(g)
if err != nil {
	return err
}
for _, e := range reduced.AllEdges() {
	fmt.Println(e.Source().Label(), "->", e.Destination().Label())
}

Example graphs

More in Dependencies

  • Descendants: Finds every vertex reachable from a vertex, such as all the jobs that wait for one step of a build.
  • Ancestors: Finds every vertex that can reach a vertex, such as all the courses one course needs first.
  • Affected: Finds the changed vertices and every vertex reachable from them, such as all the cells a spreadsheet edit recomputes.

All algorithms