ConceptComplete

Trees and Networks - Core Definitions

Trees are fundamental structures in computer science and mathematics, representing hierarchical relationships and providing efficient data organization. They are special graphs with unique connectivity properties that make them tractable for many algorithmic problems.

DefinitionTree

A tree is a connected acyclic graph. Equivalently, a tree is a connected graph where removing any edge disconnects it, or a graph where there is exactly one path between any pair of vertices.

A forest is a graph where each connected component is a tree (an acyclic graph).

A leaf is a vertex of degree 1. An internal vertex has degree at least 2.

DefinitionRooted Tree

A rooted tree is a tree with one designated vertex called the root. This induces a parent-child relationship: for any vertex vrootv \neq root, its parent is the unique vertex on the path from vv to the root. Vertices with the same parent are siblings. A vertex with no children is a leaf.

The height of a vertex is its distance from the root. The depth or level is the same as height. The height of the tree is the maximum height among all vertices.

A binary tree is a rooted tree where each vertex has at most two children (designated as left and right).

The rooted tree structure naturally models hierarchical organizations like file systems, organizational charts, and decision trees.

ExampleProperties of Trees

For a tree TT with nn vertices:

  1. TT has exactly n1n-1 edges
  2. Adding any edge creates exactly one cycle
  3. Removing any edge disconnects TT into exactly two components
  4. There is exactly one path between any two vertices

These properties are equivalent characterizations of trees.

DefinitionSpanning Tree

A spanning tree of a connected graph GG is a subgraph that is a tree and includes all vertices of GG.

Every connected graph has at least one spanning tree (found by BFS or DFS). The minimum spanning tree (MST) problem asks for a spanning tree with minimum total edge weight.

Famous MST algorithms include:

  • Kruskal's algorithm: Sort edges by weight, add edges if they don't create cycles
  • Prim's algorithm: Grow tree from a starting vertex, always adding the minimum-weight edge connecting tree to non-tree vertices
  • Borůvka's algorithm: Repeatedly find minimum-weight edge for each component and merge components
DefinitionCayley's Formula

The number of labeled trees on nn vertices is nn2n^{n-2}.

For example, there are 332=33^{3-2} = 3 labeled trees on 3 vertices (the three distinct ways to connect vertices 1, 2, 3 as a path).

This can be proven using Prüfer sequences: bijection between labeled trees and sequences of length n2n-2 with entries from {1,,n}\{1, \ldots, n\}, giving nn2n^{n-2} sequences.

Remark

Trees appear throughout computer science: binary search trees, heaps, B-trees for databases, decision trees in machine learning, parse trees in compilers, DOM trees in web browsers, and spanning trees in network protocols. The special structure of trees enables efficient algorithms: tree traversals (DFS, BFS) run in linear time, and many NP-hard graph problems become polynomial-time solvable when restricted to trees. Treewidth measures how "tree-like" a graph is, with many algorithmic implications.

Understanding trees provides essential tools for algorithm design and structural analysis in discrete mathematics.