Self-balancing Binary Search Tree implementation in C. Maintains O(log n) time complexity for insert, delete, and search using rotations and recoloring.
make
./rbtmake clean| Operation | Time Complexity |
|---|---|
| insert | O(log n) |
| delete | O(log n) |
| search | O(log n) |
| find min | O(log n) |
| find max | O(log n) |
rbtree/
├── include/
│ └── rbtree.h
├── src/
│ ├── insert.c
│ ├── delete.c
│ ├── rotations.c
│ ├── rbtree.c
│ └── utils.c
├── main.c
└── Makefile
- Each node is either red or black
- Root is always black
- All NULL leaves are black
- No two consecutive red nodes
- Every path from root to NULL has equal number of black nodes
- Insert uses standard BST insertion followed by
fix_insertto restore properties - Delete handles all three BST cases and resolves double-black using
fix_delete - Rotations (
left_rotate,right_rotate) maintain tree structure fileciteturn1file0 - Level-order traversal is used for tree visualization
- Duplicate insertions are rejected
Interactive CLI menu:
1. Insert
2. Delete
3. Search
4. Find Minimum
5. Find Maximum
6. Delete Minimum
7. Delete Maximum
8. Display Tree
9. Exit