Tree Terminology Root Leaf Height Depth Level
📖 Scenario: Imagine you are organizing a family tree. Each person is a node. You want to understand basic terms like root (oldest ancestor), leaf (person with no children), height (longest path to a leaf), depth (distance from root), and level (depth + 1).
🎯 Goal: You will create a simple tree structure in TypeScript and write code to identify the root, leaves, calculate height, depth, and level of nodes.
📋 What You'll Learn
Create a tree with exact nodes and connections
Define a variable for the root node
Write a function to find all leaf nodes
Write a function to calculate height of the tree
Write a function to calculate depth of a given node
Print the root, leaves, height, and depth of a specific node
💡 Why This Matters
🌍 Real World
Trees are used in family trees, file systems, organization charts, and many hierarchical data representations.
💼 Career
Understanding tree terminology and traversal is essential for software developers working with data structures, databases, and UI components.
Progress0 / 4 steps