Counting Edges in a Forest

Count edges in a forest by adding the edge counts of its disjoint tree components.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Compute three components
  2. Check the premise
  3. Derive total edges from sizes of the components
  4. Use component changes to check incremental updates

Each nonempty tree with \(n\) vertices has \(n-1\) edges. Rooting it assigns one parent edge to each vertex other than the root.

Compute three components

A forest with components of sizes four, two, and one has 3, 1, and 0 edges, totaling four. Its vertex count is seven and its component count three. The formula \(n-c\) follows from adding over components.

Check the premise

A triangle with an isolated vertex has four vertices and three edges but is not a single tree. Counting edges only works for the stated forest condition. See tree as a graph for connectivity and acyclicity.[1]

Derive total edges from sizes of the components

If a forest has components with four, three and one vertices, the components contribute three, two and zero edges. On eight vertices and three components, the total is five. The formula follows by summing the tree identity within each component. See induction on tree shapes.

Vertices per component: 4,3,1
Edges per component:    3,2,0
Totals: n=8, c=3, m=5
m = n - c

Use component changes to check incremental updates

Adding an edge between disconnected components decreases the component count by one and increases the edge count by one. Adding an edge inside a component creates a cycle and leaves the forest model. Test isolated vertices as components of one.

References

  1. Eric Lehman, F. Thomson Leighton and Albert R. Meyer, Mathematics for Computer Science ↩