An Introduction to Trees and Basic Tree Properties
Explore the basics of tree data structures including nodes, edges, and key properties such as depth, height, and subtrees. Learn common tree types like binary and N-ary trees and their importance in algorithms. This lesson prepares you to understand hierarchical data and foundational concepts needed for coding interviews using C++.
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 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.
- 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 that doesn’t have any Child Nodes.
- Ancestor Nodes: the nodes