Tree Properties &
Traversal Concepts
Master the fundamental structure of trees in discrete mathematics: properties, key theorems, and the three classical traversal orders that unlock efficient data processing.
What Is a Tree?
A tree is a connected, acyclic graph. It provides a hierarchical structure where every pair of vertices is connected by exactly one simple path: no loops, no redundant edges.
Key Terminology
Why Trees Matter
Trees are everywhere in computer science and mathematics. They model hierarchies (file systems, organizational charts), enable efficient search (binary search trees), and underpin algorithms (spanning trees, expression parsing).
The Tree Characterization Theorem
The \( n - 1 \) Edge Rule
Binary vs General Trees
| Binary Tree | General Tree | |
|---|---|---|
| Max children per node | 2 (left, right) | Unlimited |
| Max nodes at depth \( d \) | \( 2^d \) | No fixed limit |
| Max total nodes (height \( h \)) | \( 2^{h+1} - 1 \) | No fixed limit |
| Traversal patterns | In/Pre/Post/Level | Pre/Post/Level |
| Common use | Search, heaps, expressions | File systems, XML/HTML DOM |
Three Classical Traversals
A tree traversal is a systematic way to visit every node exactly once. The three depth-first traversals differ only in when you process the root relative to its subtrees:
How to Traverse a Binary Tree
Example: Pre-order Traversal
Example: In-order Traversal
Example: Post-order Traversal
Level-order Traversal (BFS)
Unlike depth-first traversals, level-order visits nodes layer by layer, from left to right at each depth. It uses a queue instead of recursion.
Spanning Trees
A spanning tree of a connected graph \( G \) is a subgraph that includes all vertices of \( G \) and is itself a tree. It keeps the graph connected using the minimum number of edges.
Expression Trees
An expression tree represents an arithmetic expression. Internal nodes hold operators; leaves hold operands. The three traversals produce different notations:
Common Mistakes
Traversal Summary
| Pre-order | In-order | Post-order | Level-order | |
|---|---|---|---|---|
| Visit root | Before subtrees | Between subtrees | After subtrees | By depth layer |
| Strategy | DFS (stack) | DFS (stack) | DFS (stack) | BFS (queue) |
| Notation | Prefix (Polish) | Infix (standard) | Postfix (RPN) | N/A |
| Tree type | Any | Binary only | Any | Any |
Question 1 of 5
A tree has 12 vertices. How many edges does it have?
Question 2 of 5
Given the binary tree below, what is the in-order traversal?
Question 3 of 5
Which statement is always true about a tree?
Question 4 of 5
The post-order traversal of an expression tree produces which notation?
Question 5 of 5
A connected graph with 8 vertices and 7 edges is guaranteed to be: