Graphs: Algorithmic Thinking Luay Nakhleh
Graphs: Algorithmic Thinking Luay Nakhleh
Algorithmic Thinking
Luay Nakhleh
Department of Computer Science
Rice University
Why Graphs?
Biological networks
Maps
Social networks
...
Graphs:
Basic Definitions
Directed graph
Undirected graph
1
: node
(or, vertex)
2
{1,2}
: edge
: directed edge
(1,2)
5
Graphs
E(VV) is a set of ordered pairs, each of which corresponds to a directed edge in the
graph G.
Basic Terminology
Degree Distribution
Degree Distribution
a
p0=1/7
p3=1/7
p1=1/7 p2=1/7
p4=3/7
pk = 1
k=0
10
Basic Terminology
12
Graph Representation:
Adjacency Lists
Adjacency lists specify the nodes that are adjacent to each node of the
graph.
Node
a
b
c
d
e
Adjacent nodes
b, c, e
a
a, d, e
c, e
a, c, d
Graph Representation:
Adjacency Lists
Adjacency lists specify the nodes that are adjacent to each node of the
graph.
Node
a
b
c
d
e
Adjacent nodes
b, c, e
a
a, d, e
c, e
a, c, d
Node
a
b
c
d
e
Adjacent nodes
b, c, e
a
a, d, e
c, e
a, c, d
{a: set([b,c,e]),
b: set([a]),
c: set([a,d,e]),
d: set([c,e]),
e: set([a,c,d])}
14
Graph Representation:
Adjacency Matrices
AG
When the graph is sparse, i.e., contains relatively few edges (relative
to what?), it is usually preferable to use adjacency lists (Why?)
When the graph is dense, i.e., contains relatively many edges (again,
relative to what?), it is usually preferable to use adjacency matrices
(Why?)
16
Graph Connectivity:
Paths
A path is simple if it does not contain the same node more than once.
A cycle is a simple path that begins and ends at the same node.
A path (not necessarily simple) that begins and ends at the same node is called a
circuit.
17
Graph Connectivity:
Paths
b
c
18
Graph Connectivity
H1
H2
c
H3
e
Graph Connectivity
A digraph is strongly connected if there is a path from i to j for every pair of nodes i
and j of the digraph (note that there must be a path from i to j and another from j to i).
A digraph is weakly connected if there is a path between every two nodes in the
underlying undirected graph.
The subgraphs of a directed graph G that are strongly connected but not contained in
larger strongly connected subgraphs are called the strongly connected components
(SCC) of G.
c
d
c
d