Tree

Context: FIT1008_MOC, FIT1058_MOC · a non-linear structure of chained nodes · graph-theoretically a connected acyclic Graph · specialised by the Binary Tree · the object spanning trees and forests generalise

Quick Revision

  • 🎯 Objective: hierarchical acyclic connected structure ➔ one root, no cycles; the minimal connected graph ( nodes ⇒ edges).
  • 📦 Core Components: root / leaf / inner node, depth, height | rooted (FIT1008) vs unrooted (FIT1058) | specialised by Binary Tree.
  • ⚡ Key Constraint: every operation is balanced, degenerate.

📝 Core

1. The Tree (Rooted, Edges)

  • Structure ➔ nodes + edges, one root, no cycles ➔ formally an acyclic connected graph.
  • Rooted (CS) ➔ root distinguished, edges parent→child ➔ models file systems, org charts, parse trees.
  • Edge count ➔ exactly edges (each non-root has one parent edge); add any edge ⟹ cycle, remove any ⟹ disconnect.

2. Vocabulary & Height

  • Termsroot (no parent) | leaf (no child) | inner (neither) | subtree | depth (root = 0) | height (max depth) | width.
  • Performance quantity ➔ operation cost is ➔ balanced vs degenerate (see Binary Tree).

3. Graph-Theoretic View (FIT1058, Unrooted)

  • Unrooted tree ➔ a connected acyclic graph ➔ the minimal connected graph.
  • Named theorems(T1) tree iff minimal connected | (T2) vertices ⟹ a leaf (degree-1) | (T3) vertices ⟹ edges (by induction).

⚙️ Core Implementation

Recursion is natural: a tree is a node plus subtrees, so Recursion / structural induction is the standard tool. A trie (prefix tree) shares common prefixes (tatable/tap).

🔹 Recursive height

⚖️ Core Decision Matrix

A graph is a tree iff any one equivalent condition holds:

#CharacterisationConsequence
1connected and acyclicthe base definition
2connected, minimal edges to connect
3acyclic, maximal edges without a cycle
4exactly one simple path between any pairunique routing
5add any edge ⟹ cycle; remove any ⟹ disconnectminimal connected

When It Flips: trees are the minimal connected graphs ➔ they underlie spanning trees (Prim/Kruskal). Cost is : balanced , degenerate "stick" — no better than a LinkList (a degenerate tree, one child per node).

📊 Exam Execution Trace

Manual Execution Trace

height on A(B(D,E), C):

Step / StateTrigger OpCallReturn Payload
0 (Init)leavesheight(D)/height(E)
1up to Bheight(B)
2up to Cheight(C)0
3rootheight(A)

Applied Exercise

Problem: Prove a tree on vertices has exactly edges. Derivation Proof / Hand-Calculation Walkthrough:

Final Extracted Output: — trees are the minimal connected graphs (Q.E.D.).

🧠 Active Recall