Weakly Connected
Greedy Algorithm
Simple Path
Strongly Connected Graph
Adjacency Matrix
Complexity
Time
Checking for an edge: O( 1 )
Iterating over the graph: O( v2 )
Getting all the neighbors: O( v )
Space
O(V2)
Shortest Path Problems
Tree
Spanning Tree
Paranthesis Theorum
Simple Graph
Strongly Connected Component
SCC
Minimum Spanning Tree
Adjacency List
Complexity
Time
Checking for an edge: O( V ) / O ( deg(v) ) / O( lg(V) )
Iterating over all edges: O( V + E )
Getting all the neighbors: O( V )
Space
O( V + E )
* O( deg(v) ) basically means “it depends”
* O( lg(V) ) is achievable is elements are sorted, perhaps in a BST, and you use binary search
Transpose
Kosaraju’s Algorithm
Steps
Complexity
Time
Average ⇔ Worst: O(V + E)
Space
O(V + E)
*Linear in the size of the graph
Reachable
Relaxing an edge
Adjacency Matrix
Directed vs Undirected Graph
Single Source Shortest Path
Algorithms
All Pairs Shortest Paths
Algorithms
Dijkstra’s Algorithm
Steps
Complexity
Time
Average ⇔ Worst: O( |E| + |V|*log |V| )
Average ⇔ Worst: O( (|E| + |V|) * log |V| )
Space
O(V)
*First time complexity assumes fibonacci heap (constant decrease-key)
*Second time complexity assumes binary heap (log delete-min and descrease-key)
Prim’s Algorithm
Steps
Complexity
Time
Average ⇔ Worst: O( |E| + |V|*log |V| )
Average ⇔ Worst: O( (|E| + |V|) * log |V| )
Space
O(V)
*First time complexity assumes fibonacci heap (constant decrease-key)
*Second time complexity assumes binary heap (log delete-min and descrease-key)
Loop
Adjacency List
Directed vs Undirected Graphs
Undirected Graphs
Directed graph
3 Options