GR1: Strongly Connected Components Flashcards
Runtime of DFS
O(|V| + |E|)
Runtime of BFS
O(|V| + |E|)
Runtime of Topological Sort
Just one pass of DFS to get post order numbers (O(|V| + |E|)), then one pass through an array, inserting vertices so they are ordered by post order number (O(|V|)).
O(|V| + |E|) overall.
Runtime of SCC
Two passes of DFS, so O(|V| + |E|)
Runtime of Kruskal’s
O(|E| log |V|)
Runtime of Dijkstra’s
We assume the binary min-heap implementation. Dijkstra uses the BFS framework, which is O(|V| + |E|), but each min-heap operation is O(log |V|), so overall Dijkstra’s is O((|V| + |E|) log |V|).
Runtime of Prim’s
Prim is nearly identical to Dijkstra except that it uses a different key value for its min-heap. This makes it O((m + n)log n) just like Dijkstra.