Decisions with Depth — Learning Trees in the Royal Ancestral Hall

A vast golden ancestral hall filled with towering statues and glowing threads connecting them, symbolizing a family tree hierarchy.
The Royal Ancestral Hall — every statue a node, every golden thread a relationship in the kingdom’s living family tree.
Decisions with Depth — Learning Trees in the Royal Ancestral Hall
Gurukul Tale X

Decisions with Depth — Learning Trees in the Royal Ancestral Hall

In the glowing Royal Ancestral Hall, Arjun discovers that some problems aren’t lines or loops at all — they are branching choices, spreading like a tree through generations.

Characters: Arjun, Guru Bodhi · Arc: Intermediate Gurukul · Pattern: Trees, parent/child relationships, depth, traversal (preorder, inorder, postorder)

📜 Sutra of the Hall — When One Line Isn’t Enough

Arjun stepped into the Royal Ancestral Hall. Golden statues of kings, queens, generals, sages and forgotten princes rose in tiered rows. Threads of light ran between them — parents to children, rulers to heirs.

He’d been given a simple task: “Find the third heir of the second son of the old queen.” But staring at all these branches of bloodlines, Arjun felt his brain locking up.

“Arrays I understand,” he muttered. “Even linked lists. But this? Every person has children, who have children, who have more children. The data isn't a line. It’s… stacked.”

Young Arjun standing in a grand golden hall lined with statues, overwhelmed by many generations stretching into the distance
Arjun in the Ancestral Hall — the kingdom’s history is not a single line, but a branching web of generations.

🌳 Sutra of the Tree — Root, Branches, Leaves

The hall dimmed. A familiar warm glow appeared beside Arjun as Guru Bodhi stepped forward, staff humming with light.

Guru: “When the world stops behaving like a line, it usually turns into a tree.”

He tapped his staff on the polished floor. From the stone, a glowing family tree erupted — one ancestor at the bottom, branching into children, grandchildren, and great-grandchildren.

  • Root: the original ancestor or starting point.
  • Children: nodes directly connected below a parent.
  • Leaves: nodes with no children — the current generation.
  • Level / depth: how far a node is from the root.
  • Path: the chain of nodes from root down to any person.
Guru Bodhi and Arjun standing before a glowing golden tree of light that branches into many smaller nodes
Guru Bodhi: “A tree starts from one root, then branches. Every decision, every bloodline, every hierarchy can be drawn this way.”

🧠 What Is a Tree (as a Data Structure)?

In code, a tree is a collection of nodes connected by edges, with exactly one path between any two nodes and a special node called the root.

The common vocabulary is simple but non-negotiable:

  • Parent / child — direct relationship between two connected nodes.
  • Siblings — children of the same parent (like princes and princesses of one king).
  • Subtree — a node plus all nodes beneath it.
  • Height / depth — how “tall” the tree is; how many layers of decisions or generations it holds.
Abstract golden digital tree made of glowing nodes and connections, visualizing a hierarchical structure
A tree as data: one root, many branches, clear levels. No cycles, no confusion — just structured hierarchy.

👑 Real-World Scroll — The Royal Line of Succession

In the center of the hall lay a long golden table. On it, a parchment showed the line of succession: the current king, his children, their children, and so on.

That parchment is a tree. Asking "Who rules if the king and first prince fall?" is literally a query on that tree.

Sunlit royal desk scattered with scrolls and diagrams, showing a carefully written line of succession
The royal line of succession — a tree in disguise, with the throne flowing down through generations.

🧾 Building a Tiny Royal Tree in Code

Let’s model a tiny royal family: a king, two children, and one grand-child. Nothing fancy, just the core pattern.

Python — Minimal Tree Node for a Royal Family
class Node:
    def __init__(self, name):
        self.name = name
        self.children = []  # list[Node]

    def add_child(self, child):
        self.children.append(child)


# Build a tiny royal tree
king = Node("King Arvind")
prince = Node("Prince Dev")
princess = Node("Princess Meera")
heir = Node("Young Heir Kiran")

king.add_child(prince)
king.add_child(princess)
prince.add_child(heir)

Every node knows its children. The entire royal structure is just the king node plus everything reachable from it.

🚶 Tree Traversals — Different Ways to Walk the Same Lineage

Guru Bodhi traced glowing paths along the tree: sometimes starting from the root, sometimes starting from the far-left branch.

For a binary tree (each node has up to two children: left and right), the classic traversals are:

  • Preorder: Root → Left → Right
  • Inorder: Left → Root → Right
  • Postorder: Left → Right → Root
Glowing golden tree with bright light starting at the trunk and flowing outward along branches in a clear sequence
Preorder — start at the root, then explore left branch, then right.
Golden tree with a balanced spread of glowing branches, light flowing evenly from one side through the center to the other
Inorder — read the left side, then the root, then the right: perfect for sorted output in binary search trees.
Dark golden branches stretching left and right, with the thick main trunk glowing on the far side as the final highlight
Postorder — finish children first, then the root: useful for deleting or evaluating subtrees.

🧮 Traversals in Code (Binary Tree Version)

For clarity, here’s a tiny binary-tree node. Each node has at most two children: left and right.

Python — Binary Tree Traversals
class BNode:
    def __init__(self, value, left=None, right=None):
        self.value = value
        self.left = left
        self.right = right


def preorder(node):
    # Root → Left → Right
    if node is None:
        return
    print(node.value)
    preorder(node.left)
    preorder(node.right)


def inorder(node):
    # Left → Root → Right
    if node is None:
        return
    inorder(node.left)
    print(node.value)
    inorder(node.right)


def postorder(node):
    # Left → Right → Root
    if node is None:
        return
    postorder(node.left)
    postorder(node.right)
    print(node.value)

Same tree, three different traversal orders. The choice isn’t cosmetic — it changes what question you’re really asking about the structure.

🧭 Where Trees Secretly Rule Your Code

Once you see trees, you start spotting them everywhere:

  • File systems — folders inside folders inside folders.
  • UI hierarchies — components nested inside containers.
  • Company org charts — CEO → VPs → managers → teams.
  • Game worlds — scenes made of nested objects.
  • Decision trees — each question branches into answers, then more questions.

Trees are the structure of “if this, then branch there”. Whenever choices or responsibilities split again and again, a tree is hiding underneath.