Networks, connectivity, and pathfinding algorithms
A graph is a non-linear data structure consisting of vertices (nodes) connected by edges. Unlike trees, graphs can have cycles and multiple paths between nodes.
Key properties:
Representations:
Real-world modeling: Social networks, maps, dependencies, circuits, web pages
Common applications:
Performance varies by algorithm:
Use graphs when you need to model:
Common problem types:
1. DFS (Depth-First Search) Explore as far as possible before backtracking:
2. BFS (Breadth-First Search) Explore neighbors level by level:
3. Dijkstra's Algorithm Shortest path in weighted graph (non-negative weights):
4. Union-Find (Disjoint Set Union) Track connected components efficiently:
Traversal problems:
Shortest path:
Cycle detection:
Topological sort:
Minimum spanning tree: