An Introduction to Trees and Basic Tree Properties
Explore the fundamental concepts of tree data structures in this lesson. Understand the various node types like root, child, and leaf, and learn important properties such as depth, height, and subtrees. This lesson prepares you to work with hierarchical trees and sets the foundation for advanced tree types in coding interviews.
We'll cover the following...
We'll cover the following...
Introduction
Trees consist of vertices (nodes) and edges that connect them. Unlike the linear data structures that you 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 going to be exactly one path between any two nodes.
- Root Node: A node with no parent nodes.
- Child Node: A node that is linked to an upper node (parent node).
- Parent Nodes: A node that has links to one or more child nodes.
- Sibling Node: Nodes that share the same parent node.
- Leaf Node: A node