Ancestors

Finds every vertex that can reach a vertex, such as all the courses one course needs first.

Time complexity O(V+E), gograph function dag.Ancestors.

Spreadsheet formulas

A sheet that works out the profit of one quarter. Row 2 holds the units sold from January to March, and G2 to G5 hold the price, unit cost, monthly fixed costs and tax rate. Rows 3 to 7 work out revenue, cost, profit before tax, tax and net profit, and E3, E7 and E8 hold the quarter's revenue, net profit and margin. Each edge points from a cell to a formula that reads it.

A directed graph with 25 vertices and 41 edges.

Which cells does January's net profit in B7 depend on, directly or through other formulas?

Use it in Go

jobs, err := dag.Ancestors(g, "B7")
if err != nil {
	return err
}
for _, v := range jobs {
	fmt.Println(v.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.
  • Affected: Finds the changed vertices and every vertex reachable from them, such as all the cells a spreadsheet edit recomputes.
  • Transitive reduction: Drops every edge that a longer path already implies. Each vertex still reaches the same vertices.

All algorithms