Tree Data Structure
Trees
- Collection of nodes
- One specialized node is the root.
- A node has one parent (unless it is the root)
- A node has zero or more children. Each node can have any number of children.
- Real-world “trees”:
- Organizational hierarchies
- Some family trees
- Some uses:
- Directory structure on a hard drive
- Sorted collections
| Operations Provided | Efficiency (only if the tree is balanced) |
|---|---|
| Find | O(log n) |
| Add/remove | O(log n) |
TODO
- depth first searches
- breadth first searches