Graph
Graph types
Implementation
class Graph {
private final int V;
private int E;
List<List<Integer>> adjList;
public Graph(int v) {
this.V = v; this.E = 0;
adjList = new ArrayList<List<Integer>>();
for (int i = 0; i < n; i++) {
adjList.add(new ArrayList<Integer>());
}
}
public void addEdge(int v, int w) {
adjList.get(v).add(w);
adjList.get(w).add(v);
E++;
}
public List<Integer> adj(int v) {
return adjList.get(v);
}
}Topological sorting
DFS
BFS
Cycle detection
Shortest Path problem
Simple BFS
Dijkstra's Algorithm
Bellman–Ford Algorithm
Shortest Path Faster Algorithm (SPFA) - improvement of the Bellman-Ford
Floyd–Warshall algorithm
Last updated