What is a Tree?
Explore the fundamental concepts of tree data structures in this lesson. Understand the different types of nodes, including root, parent, child, and sibling nodes, as well as important terminology like sub-trees, degree, depth, level, and height. This knowledge helps you grasp how trees are organized and their properties, essential for coding interview preparation.
We'll cover the following...
We'll cover the following...
Introduction
In this lesson, we will learn a hierarchical data structure known as a Tree. A tree consists of nodes (vertices) that are connected using pointers (edges). Trees are similar to Graphs; the key differentiating point is that a cycle cannot exist in a Tree.
The basic structure of a tree consists of the following components:
- Nodes: Hold data
- Root: The uppermost node of a tree
- Parent Node: A node which is connected to one or more nodes on the lower level (Child Nodes).
- Child Node: A node which is linked to an upper node (Parent Node)
- Sibling Node: Nodes that have the same Parent Node
- Leaf Node – A node that doesn’t have any