Structures & Algorithms
Comprehensive guide to Tree variations, Heap properties, and Graph algorithms.
Tree Classifications
Full Binary Tree
Every node has either 0 or 2 children.
Used in Huffman Coding
Complete Binary Tree
Filled level-by-level, left-to-right.
Basis for Binary Heaps
Perfect Binary Tree
All internal nodes have 2 children, leaves at same depth.
Nodes = 2^(h+1) - 1
Balanced Structures
Binary Search Tree
Unbalanced
Standard ordering: Left < Parent < Right.
AVL Tree
Self-Balancing
Strictly balanced (height diff ≤ 1). Guaranteed O(log n) lookups.
Red-Black Tree
Self-Balancing (Color Properties)
Enforces balance via color rules (Red/Black).
• No two red nodes adjacent.
• Black-height uniform paths.
Algorithms
DFS Traversals
- Preorder: Root → Left → Right
- Inorder: Left → Root → Right
- Postorder: Left → Right → Root
BFS (Level Order)
Explores neighbors layer by layer using a Queue. Finds shortest path in unweighted graphs.
Queue-basedMinimum Spanning Tree
- Prim's: Greedy node-based approach. Grows from start node.
- Kruskal's: Greedy edge-based approach using Union-Find to avoid cycles.