Data Structures and Algorithms

Trees

Introduction to Trees

Definition: Trees are hierarchical data structures with parent-child relationships, unlike linear structures like arrays or linked lists.
Examples:
Family Tree: Represents relationships from ancestors to descendants.
Computer Folder Structure: Organizes folders and files hierarchically.
Key Components:
Root: The topmost node.
Edges: Connections between nodes.
Nodes: Elements holding data and child references.
Leaf Nodes: Nodes without children.

Why Use Trees?

Applications:
Decision Trees: For decision-making processes.
Hierarchical Data: For organizing complex, layered information.
Advantages: Trees represent branching structures efficiently, unlike linear data structures.

Basic Tree Terminology

Parent: A node with children.
Child: A node descending from another.
Subtree: A node and its descendants.
No Cycles: Trees are acyclic, unlike graphs.

Binary Trees

Definition: A tree where each node has at most two children.
Types:
Full Binary Tree: Nodes have 0 or 2 children.
Complete Binary Tree: All levels fully filled except possibly the last.
Perfect Binary Tree: All internal nodes have 2 children; all leaves are at the same level.
Balanced Binary Tree: Height difference between left and right subtrees is at most one.
Degenerate Tree: Each node has only one child, resembling a linked list.
For more detailed information, refer to the Notion link:
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.