A tree is a connected graph with no cycles. Trees represent hierarchies such as file systems, family trees and decision structures.

Tree properties

For a graph T with n vertices, the following statements are equivalent:

  • T is a tree (connected, no cycle).
  • There is exactly one path between any two vertices.
  • T is connected and has exactly n − 1 edges.
  • T has no cycle and n − 1 edges.
  • Removing any edge disconnects it; adding any edge creates a cycle.

Every tree with at least two vertices has at least two leaves (vertices of degree 1).

A rooted tree has one vertex chosen as the root; each other vertex has a parent and possibly children. The height is the longest path from the root to a leaf. A binary tree has at most two children per vertex.

Spanning trees

A spanning tree of a connected graph G is a subgraph that is a tree and contains all vertices of G. It keeps the graph connected using the fewest edges, n − 1.

Example: A triangle with vertices A, B and C has three spanning trees, each made by removing one of the three edges.

To find one, remove an edge from some cycle and repeat until no cycle remains, or grow a tree by adding edges that reach new vertices.

Minimum spanning tree

In a weighted graph, a minimum spanning tree (MST) is a spanning tree with the smallest total weight. Two standard algorithms:

  • Kruskal: sort edges by weight; add the next edge if it does not form a cycle.
  • Prim: start from a vertex and repeatedly add the cheapest edge to a new vertex.

Example: Edges AB = 1, BC = 2, AC = 3, CD = 4, BD = 5. Kruskal takes AB (1), BC (2), skips AC (it would make a cycle), takes CD (4). Total weight is 7 with 3 edges for 4 vertices.

MSTs are used to lay cables or pipes at least cost.

Common mistakes

  • Thinking a spanning tree is unique. A graph can have many.
  • Forgetting that a spanning tree has exactly n − 1 edges.

Practice questions

  1. Define a tree. How many edges does a tree with 10 vertices have?
  2. What is a spanning tree?
  3. How many spanning trees does a cycle of 5 vertices have?
  4. State Kruskal's algorithm.
  5. Find an MST for edges AB = 4, BC = 1, AC = 2, CD = 3.

Answers to the practice questions

  1. A connected graph with no cycle; 9 edges.
  2. A subgraph that is a tree containing all vertices.
  3. 5 (remove any one edge).
  4. Sort edges by weight and add each one that does not form a cycle.
  5. BC (1), AC (2), CD (3): total weight 6.

Sources

  • Official BCA syllabus Mathematics Foundations to Computer Science I, course code CC101, Unit III
  • Kolman, Busby and Ross, Discrete Mathematical Structures, 6th edition, Pearson