04_data_structures
04_data_structures
## Trees
### Binary Trees
- Each node has at most two children
- Binary Search Tree: left < parent < right
- AVL Tree: self-balancing BST
- Red-Black Tree: self-balancing with O(log n) operations
### B-Trees
- Generalization of BST
- Used in databases and file systems
- Self-balancing
- Optimized for systems with slow data access (disk)
## Heaps
- Binary heap: complete binary tree
- Min-heap: parent ≤ children
- Max-heap: parent ≥ children
- Operations: Insert O(log n), Extract-min/max O(log n)
- Heapify: O(n)
- Used in priority queues, heap sort
## Hash Tables
- Key-value storage with average O(1) operations
- Collision handling: chaining or open addressing
- Load factor affects performance
- Hash function requirements: uniform, efficient, deterministic
## Practice Problems:
1. Implement a Min-Heap with insert and extract-min operations
2. Design a LRU (Least Recently Used) Cache
3. Implement a Trie for autocomplete functionality
4. Create a self-balancing BST