Heaps and Graphs
📖 Introduction
🏔️ Heaps
Heap Property
# Min Heap: parent ≤ children (root is minimum)
# Max Heap: parent ≥ children (root is maximum)
# Array representation (0-indexed):
# Parent of i: (i - 1) // 2
# Left child of i: 2 * i + 1
# Right child of i: 2 * i + 2Heap Implementation
Heapify: Building a Heap
Python's heapq Module
Heap Time Complexity
Operation
Time
📊 Heap Problems
Kth Largest Element
Top K Frequent Elements
Merge K Sorted Lists
Find Median from Data Stream
🕸️ Graphs
Graph Terminology
Graph Representations
Comparison
Representation
Space
Check Edge
Get Neighbors
Add Edge
🔍 Graph Traversals
Breadth-First Search (BFS)
Depth-First Search (DFS)
BFS vs DFS
Aspect
BFS
DFS
📊 Common Graph Problems
Number of Islands
Clone Graph
Course Schedule (Cycle Detection)
Word Ladder
Bipartite Graph
📝 Practice Exercises
Exercise 1: K Closest Points to Origin
Exercise 2: Surrounded Regions
Exercise 3: Network Delay Time
🔑 Key Takeaways
🚀 What's Next?
📚 References
Last updated