DATA STRUCTURES/Student Engineering Notebook
Page 03·notes
TREE FUNDAMENTALS, TRAVERSALS & BINARY SEARCH TREES—~34 MIN READ

Binary Tree Axioms, Degree Theorems & Traversal Reconstruction

“Handshaking lemma on trees, n0 = n2 + 1 proof, Catalan structural count, and unique tree reconstruction from traversals.”

1.The Fundamental Degree Theorem: n0 = n2 + 1

Let T be an arbitrary binary tree with n nodes and E edges. Partition the nodes by their out-degree (number of children):

- n_0: Nodes with 0 children (Leaves).

- n_1: Nodes with 1 child.

- n_2: Nodes with 2 children.

Total nodes: n = n_0 + n_1 + n_2.

Proof of Degree Relation:

1. Every node in a tree except the root has exactly 1 incoming edge. Therefore: E = n - 1.

2. Each degree-1 node contributes 1 outgoing edge, and each degree-2 node contributes 2 outgoing edges. Therefore: E = n_1 + 2 * n_2.

3. Equating the two expressions for E:

n - 1 = n_1 + 2 * n_2

(n_0 + n_1 + n_2) - 1 = n_1 + 2 * n_2

n_0 - 1 = n_2 implies n_0 = n_2 + 1.

This fundamental law holds unconditionally for every binary tree.

2.Tree Traversals & Unique Reconstruction Theorems

There are four standard systematic traversal strategies:

1. Pre-Order (N-L-R): Visit Node, traverse Left subtree, traverse Right subtree.

2. In-Order (L-N-R): Traverse Left subtree, visit Node, traverse Right subtree.

3. Post-Order (L-R-N): Traverse Left subtree, traverse Right subtree, visit Node.

4. Level-Order: Breadth-First traversal using a FIFO queue.

Reconstruction Theorem:

- Pre-order's first element is always the root. Locate this root in the In-order traversal. All elements to the left of the root in In-order belong to the left subtree; all elements to the right belong to the right subtree. Recursively reconstruct.

- Why Pre-order + Post-order fails: If a node has a single child, Pre-order [A, B] and Post-order [B, A] cannot determine whether B is a left child or a right child.

WORKED EXAM ANALYSIS · STEP-BY-STEP DERIVATIONOriginal Practice Problem · Modeled on GATE Pattern (2 Marks)

3. Worked Problem: Node Count & Traversal Reconstruction

⚠️ Pitfall Warning:

Do not confuse internal nodes with degree-2 nodes. Degree-1 nodes are internal nodes that do NOT count toward n2.

Problem: A binary tree has 14 leaf nodes and a total of 35 nodes. How many nodes have exactly 1 child? Also determine the total number of edges.

Step 1: Identify given parameters:

n_0 = 14 (leaves), Total nodes n = 35.

Step 2: Apply leaf vs degree-2 theorem:

n_0 = n_2 + 1

14 = n_2 + 1 => n_2 = 13 nodes.

Step 3: Solve for degree-1 nodes n_1:

Total nodes n = n_0 + n_1 + n_2

35 = 14 + n_1 + 13 = 27 + n_1

n_1 = 35 - 27 = 8 nodes.

Step 4: Compute total edges E:

E = n - 1 = 35 - 1 = 34 edges.

Check with outgoing edges: n_1 + 2n_2 = 8 + 213 = 8 + 26 = 34 edges. Verified!

Final Answer: 8 nodes have exactly 1 child, and the tree has 34 edges.

SOURCE TRANSPARENCY & CITATIONS

Primary Academic References & Exam Sources

Every concept in Notes From a B.Tech Brain is synthesized from authoritative academic texts, seminal peer-reviewed research, verified exam archives, and renowned university lectures.

Curated University Lecture Series
Introduction to Algorithms (4th Edition) ·
LECTURE SERIES
RECOMMENDED YOUTUBE EDUCATORS & FULL-COURSE PLAYLISTS

Curated for clarity, rigorous numerical solving, and semester excellence:

Abdul Bari · Data Structures & Algorithms↗Instructor: Abdul Bari · Covers: Trees, graphs, hashing, sorting — with visual algorithm animations

Visual thinkers who want to see each algorithm step animated clearly.

Open YouTube↗
Gate Smashers · Data Structures Full Course↗Instructor: Varun Singla · Covers: Arrays, linked lists, trees, BST, AVL, heaps, hashing — GATE numericals

GATE-targeted coverage with step-by-step GATE PYQ walkthroughs.

Open YouTube↗