LOGBOOK

HELP

Quiz Entry - updated: 2026.11.27

What is a forest, and how many edges does a forest with $n$ vertices and $k$ trees have?

A forest is an undirected graph without cycles; unlike a tree it need not be connected. Its connected components are trees, so a forest of $k$ trees on $n$ vertices has $n - k$ edges, one edge fewer than vertices for every tree.

Every tree is a forest with $k = 1$, and a vertex without any edge is a tree too, with one vertex and no edges. The forest in the picture has 9 vertices in 3 trees (a single vertex and two trees of 4 vertices), hence $9 - 3 = 6$ edges.

Counting edges therefore tells you something about structure. A graph with $n$ vertices and no cycles has at most $n - 1$ edges, and exactly $n - 1$ only if it is connected, a single tree. A connected graph needs at least $n - 1$ edges, and with exactly $n - 1$ it is a tree.

Go deeper:

From Quiz: ADS / Graphs: Basics, Representations and Spanning Trees | Updated: Nov 27, 2026