10.2 Trees, Properties of Spanning Trees & Cayley's Formula
💡 Core Intuition: The 3-Second Mental Model
🍳 The Everyday Analogy: The Lean Corporate Org Chart & Cable Television Backbone
Think of trees as the most cost-efficient communication network:
- The Tree Contract (Zero Redundancy, Zero Islands): Imagine laying fiber-optic cables to connect offices. If there are any loops, you wasted money buying redundant cables. If there are any disconnected offices, people cannot communicate. A Tree connects all offices using the absolute minimum possible cables: exactly cables!
- The Fragility of a Tree: Because there is zero redundancy:
- Cutting any single cable splits the network into two disconnected islands (every edge is a bridge).
- Adding any new cable between two existing offices immediately creates a redundant loop (a cycle).
- Cayley's Formula & Prüfer Codes: How many different ways can you wire numbered computers together as a tree? Arthur Cayley proved in 1889 that there are exactly distinct labeled trees. Heinz Prüfer created a brilliant loss-less compression algorithm: any tree on vertices compresses into a unique phone number of length !
💻 Bridging to Computer Science: DOM Trees, ASTs, Spanning Tree Protocol & File Systems
In computer systems:
- Spanning Tree Protocol (STP / IEEE 802.1D): Ethernet switches run STP to dynamically disable redundant bridge ports, preventing devastating broadcast radiation storms by maintaining a loop-free logical spanning tree.
- Compilers & Parsers: Abstract Syntax Trees (ASTs) represent the hierarchical grammatical structure of source code without circular loops.
- Hierarchical File Systems: Unix directory structures form rooted trees where directories branch down to file leaves.
🌳 The 6 Equivalent Characterizations of a Tree
A tree is one of the most mathematically overdetermined structures in computer science.
- Tree: An undirected graph is a Tree if and only if it is connected and acyclic (contains no simple cycles).
- Forest: An undirected graph is a Forest if and only if it is acyclic. Each connected component of a forest is a tree.
- If a forest has vertices and connected components, the total number of edges is:
The 6 Equivalent Axiomatic Characterizations of a Tree
Proving any ONE of these properties automatically proves all other five
1. Connected & Acyclic
Standard Definition- G is connected and contains zero simple cycles.
- The classical baseline definition of a tree.
2. Connected with n - 1 Edges
Edge Budget- G is connected and |E| = |V| - 1.
- The minimal edge count required for any graph to remain connected.
3. Acyclic with n - 1 Edges
Cycle-Free Budget- G has no cycles and |E| = |V| - 1.
- Forces all components to merge into a single connected entity.
4. Unique Simple Path
Deterministic Routing- There exists EXACTLY ONE unique simple path between every pair of vertices.
- Zero detours, zero alternative routes.
5. Minimally Connected
All-Bridge Network- G is connected, but removing ANY edge e disconnects G: c(G - e) = 2.
- Every single edge in a tree is an articulation bridge!
6. Maximally Acyclic
Saturated Loop-Free- G has no cycles, but adding ANY edge between non-adjacent vertices creates a unique cycle.
Every tree with vertices contains at least TWO leaves (vertices of degree 1)!
Proof by Handshaking Lemma: Suppose for contradiction that a tree with vertices has at most 1 leaf.
- A connected graph with vertices cannot have any isolated vertices ( for all ).
- If there is at most 1 leaf, then at least vertices must have degree :
- But by the Handshaking Lemma, for any tree with :
- This yields , an impossible contradiction! Therefore, every tree with vertices must contain at least two vertices of degree 1.
🌐 Spanning Trees & Fundamental Cycle/Cut-Set Duality
Let be a connected graph:
- A Spanning Tree of is a subgraph that is a tree containing all vertices of .
- Number of tree branches: .
- Chords (Co-Tree Edges): The remaining edges in that do not belong to :
- Number of chords: (also called the Circuit Rank or Cyclomatic Number of ).
- Fundamental Cycle: Adding any single chord edge to a spanning tree creates exactly one unique simple cycle. The collection of cycles formed by adding each chord independently forms the basis of all cycles in . Total fundamental cycles = .
- Fundamental Cut-Set: Removing any single tree branch splits into two disconnected trees ( and ). The set of all edges in connecting and forms a fundamental cut-set. Total fundamental cut-sets = .
🔢 Cayley's Tree Formula & Prüfer Sequences
How many distinct labeled trees can be constructed on vertices?
The number of distinct labeled trees on vertices (or the number of spanning trees of the complete graph ) is:
- For : tree.
- For : tree.
- For : trees.
- For : trees.
- For : trees.
The Prüfer Sequence Bijection Pipeline
Lossless 1-to-1 mapping between labeled trees on n vertices and sequences of length n - 2
Identify Smallest Leaf
Find the leaf vertex v (degree = 1) with the smallest numerical label.
Record Neighbor & Delete
Append the label of v's unique neighbor to the Prüfer sequence. Delete vertex v and its incident edge.
Sequence of Length n - 2
Stop when exactly 2 vertices remain. The generated list has length n - 2 with elements from {1, 2, ..., n}.
deg(v) = 1 + count(v)
In the original tree, the degree of vertex v equals 1 plus the number of times v appears in the Prüfer sequence!
📝 Step-by-Step Worked Examples
Example 1: Constructing the Prüfer Sequence of a Labeled Tree
Problem Statement: Consider a labeled tree with vertices and edges:
- Encode this tree into its unique Prüfer sequence.
- Verify the degree formula .
Step-by-Step Solution:
-
Step 1: Encoding into Prüfer Sequence
- Initial leaves (): .
- Smallest leaf is . Its neighbor is .
- Append to sequence. Delete leaf .
- Remaining vertices: . Sequence:
(4).
- Current leaves: .
- Smallest leaf is . Its neighbor is .
- Append to sequence. Delete leaf .
- Remaining vertices: . Sequence:
(4, 4).
- Current leaves: .
- Smallest leaf is . Its neighbor is .
- Append to sequence. Delete leaf .
- Notice: Now vertex only connects to , so vertex becomes a leaf!
- Remaining vertices: . Sequence:
(4, 4, 4).
- Current leaves: (since ).
- Smallest leaf is . Its neighbor is .
- Append to sequence. Delete leaf .
- Remaining vertices: . Sequence:
(4, 4, 4, 5).
- Exactly vertices remain (). We halt!
- Final Prüfer Sequence:
(4, 4, 4, 5)(Length = ).
-
Step 2: Verify the Degree Formula
- Sequence:
(4, 4, 4, 5). - Frequency of vertex : . (Leaf!).
- Frequency of vertex : . (Leaf!).
- Frequency of vertex : . (Leaf!).
- Frequency of vertex : .
- Frequency of vertex : .
- Frequency of vertex : . (Leaf!).
- Original degrees match the tree edges perfectly!
- Sequence:
Key Takeaway: Leaves are vertices that never appear in the Prüfer sequence, while high-degree hub vertices appear repeatedly.
Example 2: Counting Labeled Trees with Specific Vertex Degrees
Problem Statement: How many labeled trees on vertices exist such that vertex has degree 3?
Step-by-Step Solution:
-
Step 1: Relate Degree to Prüfer Frequency
- By the degree invariant:
- Since , vertex must appear exactly: in the Prüfer sequence of length .
-
Step 2: Combinatorial Choice of Positions and Fillers
- The Prüfer sequence has open slots:
(_ , _ , _). - Number of ways to choose which slots contain the label :
- The remaining slot must be filled by any of the other vertex labels ():
- Total valid Prüfer sequences:
- The Prüfer sequence has open slots:
Key Takeaway: To count trees with specified vertex degrees, use the multinomial distribution over the slots of the Prüfer code!
🎯 Exam & Interview Pitfall Check
Question 1: If a graph has vertices and edges, is it guaranteed to be a tree? Key Focus Points: No! A graph with vertices and edges is only a tree if it is connected (or acyclic). If it is disconnected, it could consist of a triangle (, 3 vertices, 3 edges) and an isolated vertex (, 1 vertex, 0 edges). Total vertices = 4, total edges = 3 (), but it has a cycle and is disconnected! Both conditions ( edges AND connected/acyclic) are strictly required.
Question 2: How many edges must be deleted from a connected graph to produce a spanning tree? Key Focus Points: A spanning tree strictly requires edges. Therefore, you must delete exactly:
This quantity is the Cyclomatic Number (Circuit Rank) of the graph, representing the exact number of independent cycles in .
Trap 1: Forgetting that Cayley's formula applies ONLY to labeled trees Why it fails: counts labeled trees (where vertices are numbered 1 to ). For unlabeled trees (isomorphism classes), the counts are much smaller: for , there are 16 labeled trees, but only 2 unlabeled trees (the star graph and the path graph ).
Trap 2: Assuming every edge in a general graph is a bridge Why it fails: In a general graph with cycles, edges belonging to cycles are not bridges. Only in a tree is every single edge guaranteed to be a bridge!