Search⌘ K

An Introduction to Trees and Basic Tree Properties!

Explore the fundamentals of trees, including their structure, common terms like root, child, and sibling nodes, and properties such as depth and height. Understand different tree types and their relevance for coding interviews, preparing you to implement and work with trees effectively in JavaScript.

Introduction #

Trees consist of vertices (nodes) and edges that connect them. Unlike the linear data structures that we have studied so far, trees are hierarchical. They are similar to Graphs, except that a cycle cannot exist in a Tree - they are acyclic. In other words, there is always exactly one path between any two nodes.

  • Root Node: A node with no parent nodes. Generally, trees don’t have to have a root. However, rooted trees have one distinguished node and are largely what we will use in this course.
  • Child Node: A node linked to an upper node (Parent Node)
  • Parent Nodes: A node that has links to one or more Child Node
  • Sibling
...