Week11 2graph011
Week11 2graph011
Week11 2graph011
3)
▶ Introduction:
▶ Examples of Graph Models
▶ Graph Terminology
▶ Basic Graph Properties: The Handshaking Theorem
▶ Graph Representations
▶ Important Types of Graphs:
▶ Complete Graphs
▶ Cycles and Wheels
▶ Bipartite Graphs
▶ Directed Graphs
Graphs
b h z
u v
y g
d c
a
x w f
e
▶ A graph consists of a set of vertices and a set of edges.
▶ A vertex is a primitive object (a and b).
▶ An edge is an unordered pair of vertices (u and v ).
▶ Graphs are drawn as circles connected by curves.
▶ Applications label the vertices and edges with data.
▶ Example: vertices are cities and edges are driving distances.
Simple Graph
b h z
u v
y g
d c
a
x w f
e
▶ The vertices of an edge are its endpoints (u has a and b).
▶ An edge and its endpoints are incident (u and a).
▶ The endpoints of an edge are adjacent (a and b).
▶ An adjacent vertex is a neighbor (b, d, and e for c).
▶ The number of neighbors is the vertex degree (3 for c).
▶ Vertices and edges are also called nodes and links.
Terminology 2
b h z
u v
y g
d c
a
x w f
e
The sumXof the degrees of the vertices equals twice the number of
edges. deg (v ) = 2|E |
v ∈V
1 4 3
5
▶ A graph with n vertices can be represented by an n-by-n
matrix m in which mij = 1 when vi vj and 0 otherwise.
▶ The matrix m is symmetric.
▶ The space complexity is O(n2 ).
0 1 0 0 0
1 0 1 0 0
0 1 0 1 1
0 0 1 0 1
0 0 1 1 0
List Representation
1 4 3
5
▶ A graph can also be represented with an array of edge lists.
The ith element lists the vertices that are neighbors of vi .
▶ Example: ((2), (1, 3), (2, 4, 5), (3, 5), (3, 4))
▶ The space complexity is O(m + n) for a graph with n vertices
and m edges.
▶ Edge lists are generally superior for sparse graphs and inferior
for dense graphs.
Special Types of Graphs
k4 c4 w5 h3
b h
g
a d c
f
e
▶ A directed graph has ordered pairs of vertices as edges.
▶ An edge ab is drawn as an arrow from a to b.
▶ The tail of ab is a and the head is b.
▶ The matrix and edge list representations carry over.
Directed Graphs 2