Graph Blackboxes Flashcards

1
Q

EXPLORE

A

INPUT: graph G = (V, E) which is directed or undirected

OUTPUT: visited[u] set to true for all nodes u reachable from v

RUNTIME: O(m)

NOTE: ccnum, prev, post, pre are set in explore subroutine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

DFS

A

INPUT: graph G = (V, E) directed or undirected

OUTPUT:

  • -> prev[z]: parent of z
  • -> pre[z]: pre num
  • -> post[z]: post num
  • -> ccnum[z]: connected component # of vertex z (or –> SCC number if using this in SCC algorithm)

RUNTIME: O(m+n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Dijkstra’s

A

INPUT:

  • -> graph G = (V,E)
  • -> vertex s
  • -> positive edge weights w

OUTPUT:

  • -> dist[u]: distances from s to u (if possible)
  • -> prev[z]: parent index of vertex z

RUNTIME: O((n+m) * logn)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

BFS

A

INPUT:

  • -> graph G = (V,E) directed or undirected
  • -> vertex s

OUTPUT:

  • -> dist[u]: dist from s to u (in terms of number of edges)
  • -> prev[z]: parent index of vertex z

RUNTIME: O(n + m)

NOTE: used for unweighted single source shortest path

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

SCC

A

INPUT:
Graph G = (V, E), directed

OUTPUT:
Handwave: Strongly Connected Components and Metagraph

Runtime:
O(n + m)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

2-SAT

A

INPUT:
formula f in CNF with n variables and m clauses, each of size 2

OUTPUT:
boolean assignment for each variable or “no” if not satisfiable (satisfied when graph is empty)

RUNTIME:
O(n + m)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Kruskals

A

INPUT:
Directed graph G = (V,E)
Edge weights w(e)

OUTPUT:
minimum spanning tree of G

RUNTIME:
O(m logn)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Prims

A

Everything same as Kruskal’s but runtime is O(n+m logn)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Building Residual Network

A

INPUT:
G(V,E), c, f

OUTPUT:
residual graph (which includes residual capacities)

RUNTIME:
O(n + m)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly