GeorgiaTech CS-6515: Graduate Algorithms: Graphs-Book Notes Flashcards by Calvin Hoang - Brainscape
GeorgiaTech CS-6515: Graduate Algorithms: Graphs-Book Notes Flashcards by Calvin Hoang - Brainscape
GeorgiaTech CS-6515: Graduate Algorithms: Graphs-Book Notes Flashcards by Calvin Hoang - Brainscape
Q
Adjacency Matrix Time?
Defn?
Sparse or Dense?
A
Edge Check O(1)
Space O(n^2)
Undirected graphs, the matrix is symmetric (as it can be traversed in either direction)
Used on dense graph
Q
Adjacency List Time?
Defn?
Sparse or Dense?
A
Checking for edge: O(|E| + |V|)
Space: O(E)
Consists of linked list of vertices, each vertex has a list of the vertices which u has an
outgoing edge.
Q
Depth First Search
Time?
Algo?
A
Time: O(|E| + |V|) Linear Time
dfs (G):
NOTE: This top level handles the disconnected graph base by making sure to kick off a
new explore to traverse any vertex not covered by the recursion below.
for all v in V
visited(v) = false
for all v in V
if not visited(v)
explore(v)
explore(G,V)
visited(v) = true
previsit(v)
postvisit(v)
Q
A graph is connected if?
A
There is a path between any pair of vertices.
Q
What a connected components?
A
A subgraph that that every vertex is connected internally, but has no edges that
connect out to the remaining vertices.
Q
What are pre and post visit for
Algo?
Defn?
Uses?
A
previsit(v)
pre[v] = clock
clock = clock + 1
postvisit(v)
post[v] = clock
clock = clock + 1
Previsit keeps track of when a node is first discovered in the tree, post visit is the time
when all of it’s child nodes have finished being discovered.
Q
Types of edges in DFS for Directed Graph
Tree Edge
Forward Edge
Back Edge
Cross Edge
A
Tree - Main edges that are part of forest (traversal)
Forward edges - edges that lead from a node to a non child descendant
Cross Edges - not a descendant or ancestor, lead to peer that was already explored.
Back V[U[]U ]V
Q
Cycle/Acyclic
A
A Cycle can be discovered with a depth first search in linear time if it encoutnerd a
back edge.
Q
What is a topological sort of a graph (linearize)
Time?
How is it done?
A
Time: Linear
A topological sort of a graph allows it to be ordered in a way that each edge goes from
an earlier vertex to a later one. (E.g.) Gives order of precidence so that constraints
(pre conditions) of a vertex are all satistfied.
10
Q
Strongly Connected Components
A
Two nodes u and v in a directed graph are connected if there is a path from u to v and
a path from v to u.
vertexes that share this property can be parition into a disjoint set, where each
disjoint set is a “strongly connected componet” From any node in the set you can get
to any other node in the set.
Merging “Strongly Connected Components” into a meta-node will leave a dag. Every
directed graph is a dag of it’s strongly connected components.
11
Q
Strongly Connected Component Algorithm
Time:
Algo:
A
Time: Linear O(|E| + |V|)
Algo:
12
Q
Breadth First Search
Time:
Def:
A
Time: O(|V| + |E|) Linear.
Initially the queue Q consists only of s, the one node at distance 0. And for each
subsequent distance d = 1, 2, 3, . . . , there is a point in time at which Q contains all the
nodes at distance d and nothing else. As these nodes are processed (ejected off the
front of the queue), their as-yet-unseen neighbors are injected into the end of the
queue.
13
Q
Dijkstra’s Algorithm
Time
Defn
A
Based on Priority Queue (min heap/Binary)
Note: As each node is traversed it keeps a back pointer to it’s predecessor, this way
the path back to the shortest can simply traverse back the pointers.
14
Q
Algorithms capable of finding shortest paths with negative weights.
Reminder: Negative weight cycles can be detected in some cases using these
algorithms.
A
Bellman Ford = O(|V| * |E|)
15
Q
Minimum Spanning Tree
Def
Time
A
Take a graph and find the minimum weighted, acyclic tree, that keeps all nodes
connected without introducing cycles.
16
Q
Kruskal’s algorithm
time
def
A
O(|E| Log |V|).
Start with an empty graph and repeatedly add the next lightest edge that doesn’t
produce a cycle.
union by rank - starts with disjointed sets and does find and combine in log(n) time.
17
Q
Cut Property
A
In building a minimum spanning tree, if we connect two minimum spanning trees
using the lightest edge between the two of them, the result is a new minimum
spanning tree.
18
Q
Prim’s Algorithm
Time
Def
A
O(m log n)
Each iteration the smallest edge on the frontier is added to the tree, provided it
doesn’t create a cycle.
(Almost identical to dijkstra, except dijkstra uses the full path length to the node as it’s
key in the priority queue. Prim, only uses the weight of the indiviual edge on the
frontier when it is added to the priority queue.)
19
Q
Max Flow - Min Cut
Time
Def
A
Time: O(C * |E| )