next up previous
Next: About this document ... Up: CS 3345: Algorithm Analysis Previous: Chapter 7: Sorting

Chapter 9: Graph Algorithms

Graph Algorithms

G = (V, E)

where, V: set of vertices
E: set of edges (v,w), where $v, w \in V$
Directed graph
(digraph)
Adjacency
: w adjacent to v iff $(v,w) \in E$.
Edge weight
: cost associated with edge
Loop
: edge of the form (v,v)
Paths
Sequence of adjacent vertices $w_1,w_2,\ldots,w_n$
Path length
: number of edges on the path.
Simple path
: all vertices (except possibly first and last) are distinct.
Cycle
: w1=wn
Acyclic graph
: graph with no cycles.

Graph Connectivity
Connected graph
(undirected): path between every pair of vertices.
Strongly connected graph
: directed graph that is connected.
Weakly connected graph
: directed graph whose underlying graph is connected, and not strongly connected.
Complete graph
: edge between every pair of vertices (clique).

Graph Representation
Adjacency Matrix
: a $V\times V$ matrix representing edges.
Not good for sparse graphs: $O(\mid V \mid^2)$ space
Adjacency List
: list of adjacent vertices for each vertex.
$O(\mid V \mid + \mid E \mid)$ space.

Topological Sort
Procedure
1.
print vertex with no incoming edge
2.
remove printed vertex and all outgoing edges from it
3.
repeat for rest of the graph
4.
Time = $O(\mid V \mid + \mid E \mid)$

Shortest Path Algorithm
Input
: weighted graph, and a vertex S.
Goal
: find shortest weighted path from S to every other vertex.
Negative cost cycle
: cycle weight < 0.
Shortest paths are not defined in this case.
Unweighted Shortest Path

Weighted Shortest Path
Dijkstra's algorithm