Hierarchical data structures fundamentals
Section 1 of 4
Trees are hierarchical data structures that consist of nodes connected by edges. Unlike linear structures (arrays, linked lists), trees represent data in a parent-child relationship, making them perfect for organizing hierarchical information.
Basic unit containing data and links to children
Top-most node with no parent
Node with one or more children
Node connected below another node
Node with no children (terminal node)
Nodes sharing the same parent
Node on the path from root to current node
Node reachable by going down the tree
Tree formed by a node and all its descendants
Maximum number of edges from root to leaf
Number of edges from root to a node
Number of children a node has
Each node has at most 2 children (left and right)
Binary tree where left child < parent < right child
All levels filled except possibly the last (filled left to right)
All internal nodes have 2 children, all leaves at same level
Self-balancing BST where heights of subtrees differ by at most 1
Tree where each node can have up to N children
| Operation | Balanced | Worst Case |
|---|---|---|
| Search | O(log n) | O(n) |
| Insert | O(log n) | O(n) |
| Delete | O(log n) | O(n) |
| Traversal | O(n) | O(n) |