Day 13: Introduction to Trees
Introduction to Trees#
Welcome to Day 13 of our 60 Days of Coding Algorithm Challenge! Today, we’ll dive into the world of trees, a fundamental hierarchical data structure that plays a crucial role in various algorithms and applications.
What is a Tree?#
A tree is a hierarchical data structure that consists of nodes connected by edges. It is a non-linear data structure, unlike arrays, linked lists, stacks, and queues, which are linear data structures. In a tree, one node is designated as the root, and every other node is connected by a directed edge from exactly one other node. This node is called the parent of the node it connects to. The connected nodes below a given node are called its children.
Basic Terminology#
- Root: The topmost node of the tree, which has no parent.
- Node: An entity that contains a value or data, and pointers to its child nodes.
- Edge: The link between two nodes.
- Parent: A node that has child nodes.
- Child: A node that has a parent node.
- Leaf: A node that has no children.
- Sibling: Nodes that share the same parent.
- Depth: The number of edges from the root to the node.
- Height: The number of edges from the node to the deepest leaf.
- Subtree: A tree …
Keep your momentum going
Create a free account to unlock the full lesson, all 60 days, and track your progress as you go.
- Full access to all 60 daily lessons
- Track completion and build a daily streak
- Get interview-ready, one algorithm at a time
Join 2,900+ learners · 4.8/5 average rating