Log In Sign Up
Day 13

Day 13: Introduction to Trees

13/60 Days

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 #

  1. Root: The topmost node of the tree, which has no parent.
  2. Node: An entity that contains a value or data, and pointers to its child nodes.
  3. Edge: The link between two nodes.
  4. Parent: A node that has child nodes.
  5. Child: A node that has a parent node.
  6. Leaf: A node that has no children.
  7. Sibling: Nodes that share the same parent.
  8. Depth: The number of edges from the root to the node.
  9. Height: The number of edges from the node to the deepest leaf. …