1. Weighted Graph
2. Unweighted Graph
3. Undirected Graph
4. Directed Graph
Graphs whose edges or paths have values called weights. Edges value can represent weight/cost/length
There is no value or weight associated with the edge. By default, all the graphs are unweighted unless there is a value associated.
All edges are bi-directional.
For example - Friends connected on facebook
Edges are directed from one node to another.
For example - Flights Routes, Flight Fares
BFS (Breadth First Search)
DFS (Depth First Search)
Problem Statement ....
Undirected Graphs
- Weighted Graphs
- Single Source Shortest Paths (SSSP)
Single Source Shortest Path
1. BFS
2. Dijkstra's
3. Bellman Ford
All-Pairs Shortest Path
4. Floyd Warshall
Single Source Shortest Path
1. BFS
2. Dijkstra's
3. Bellman Ford
All-Pairs Shortest Path
4. Floyd Warshall
Simple BFS Algorithm
We can use BFS, for unweighted graphs!
Weighted Graphs
Single All Pairs Shortest Paths (APSP)
Dynamic Programming based algorithm.
1. BFS (SSSP on unweighted graph)
2. Dijkstra's (SSSP on weighted graph)
3. Bellman Ford (SSSP on weighted graph with -ve edges)
4. Floyd Warshall (APSP on all graphs)
DSU Data Structure
1. Find
2. Union
Problem Statement: Given a connected, undirected and weighted graph G, select a subset of edges E' such that graph G is conncected and total weight of selected edges E' is minimum.
Example
V-1 Edges to form a tree and keep the graph connected
Real Life Application
Popular Algorithms
Directed Acyclic Graphs