Lecture_08_graph_02
Lecture_08_graph_02
Lecture 8
1
Undirected graph
Example: What are the degrees and neighborhoods of the vertices in
the graphs H?
Solution:
H: deg(a) = ?, deg(b) = deg(e) = ?, deg(c) = 1, deg(d) = ?.
N(a) = {b, d, e}, N(b) = {a, b, c, d, e}, N(c) = {b},
N(d) = {a, b, e}, N(e) = {a, b ,d}.
2
Undirected graph
Example: What are the degrees and neighborhoods of the vertices in
the graphs H?
Solution:
H: deg(a) = 4, deg(b) = deg(e) = 6, deg(c) = 1, deg(d) = 5.
N(a) = {b, d, e}, N(b) = {a, b, c, d, e}, N(c) = {b},
N(d) = {a, b, e}, N(e) = {a, b ,d}.
3
Directed graph
Definition: The in-degree of a vertex v, denoted deg- (v), is
the number of edges which terminate at v. The out-degree of v,
denoted deg+(v), is the number of edges with v as their initial
vertex. Note that a loop at a vertex contributes 1 to both the indegree
and the out-degree of the vertex
4
Directed graph
Definition: The in-degree of a vertex v, denoted deg- (v), is
the number of edges which terminate at v. The out-degree of v,
denoted deg+(v), is the number of edges with v as their initial
vertex. Note that a loop at a vertex contributes 1 to both the indegree
and the out-degree of the vertex
5
Directed graph
Definition: The in-degree of a vertex v, denoted deg- (v), is
the number of edges which terminate at v. The out-degree of v,
denoted deg+(v), is the number of edges with v as their initial
vertex. Note that a loop at a vertex contributes 1 to both the indegree
and the out-degree of the vertex
6
Directed graph
Definition: The in-degree of a vertex v, denoted deg- (v), is
the number of edges which terminate at v. The out-degree of v,
denoted deg+(v), is the number of edges with v as their initial
vertex. Note that a loop at a vertex contributes 1 to both the indegree
and the out-degree of the vertex
7
Bipartite Graph
Definition: A simple graph G is bipartite if V can be partitioned
into two disjoint subsets V1 and V2 such that every edge connects a
vertex in V1 and a vertex in V2. In other words, there are no edges
which connect two vertices in V1 or in V2.
8
Bipartite Graph
Example: Show that C6 is bipartite.
9
Bipartite Graph
Example: Show that C3 is not bipartite.
10
Representation: Adjacency List
Definition: An adjacency list can be used to represent a
graph with no multiple edges by specifying the vertices that
are adjacent to each vertex of the graph.
Example:
An adjacency list for a simple graph
vertex Adjacent vertex
a b, c, e
b a
c a, d, e
d c, e
e a, d, c
11
Representation: Adjacency List
Definition: An adjacency list can be used to represent a
graph with no multiple edges by specifying the vertices that
are adjacent to each vertex of the graph.
Example:
An adjacency list for a directed graph
vertex Adjacent vertex
a b, c, d, e
b b, d
c a, c, e
d
e b, c, d
12
Adjacency Matrix
Definition: Suppose that G = (V, E) is a simple graph where
|V| = n. Arbitrarily list the vertices of G as v1, v2, … , vn. The
adjacency matrix AG of G, with respect to the listing of
vertices, is the n × n zero-one matrix with 1 as its (i, j)th
entry when vi and vj are adjacent, and 0 as its (i, j)th entry
when they are not adjacent.
Example:
0 1 1 1
1 0 1 0
1 1 0 0
1 0 0 0
13
Adjacency Matrix
Adjacency matrices can also be used to represent graphs with loops
and multiple edges.
• A loop at the vertex vi is represented by a 1 at the (i, i)th position of
the matrix.
• When multiple edges connect the same pair of vertices vi and vj, (or if
multiple loops are present at the same vertex), the (i, j)th entry equals
the number of edges connecting the pair of vertices.
0 3 0 2
3 0 1 1
0 1 1 2
2 1 2 0 14
Graph Isomorphism
Definition: The simple graphs G1 = (V1, E1) and G2 = (V2, E2) are
isomorphic if there is a one-to-one and onto function f from V1 to
V2 with the property that a and b are adjacent in G1 if and only if
f(a) and f(b) are adjacent in G2 , for all a and b in V1 . Such a
function f is called an isomorphism. Two simple graphs that are not
isomorphic are called nonisomorphic.
15
Path
A path in a graph is a continuous way of getting
from one vertex to another by using a sequence of
edges.
16
Path Length
A path of length n in an undirected graph is a
sequence of n edges e1, e2, … ,en such that each
consecutive pair ei , ei+1 share a common vertex.
17
Path and Cycle
A simple path contains no duplicate edges
(though duplicate vertices are allowed). A cycle
(or circuit) is a path which starts and ends at the
same vertex.
18
Connectivity
Let G be a dograph. Let u and v be vertices. u
and v are connected to each other if there is a
path in G which starts at u and ends at v. G is said
to be connected if all vertices are connected to
each other.
19
Connectivity in directed graph
1) Weakly connected : can get from a to b in
underlying undirected graph
2) Strongly connected : there is a path from a to
b AND from b to a in the digraph
22
Hamiltonian Circuit Problem
23
Hamilton Path
• A Hamilton path of a graph or digraph is a path that
contains each vertex exactly once, except that the end
vertices may be the same.
• A Hamilton circuit (or cycle) is a Hamilton path that is a
cycle.
• Contrast this with an Euler circuit which contains each
edge exactly once.
24
Tree
Definition: A tree is a connected undirected graph with no simple circuits.
Example:
25
Forest
Definition: A forest is a graph that has no simple circuit, but is not
connected. Each of the connected components in a forest is a tree.
Example:
26
Tree
Theorem: An undirected graph is a tree if and only if there is a
unique simple path between any two of its vertices.
Example:
27
Rooted Tree
Definition: A rooted tree is a tree in which one vertex has been
designated as the root and every edge is directed away from the
root.
28
Rooted Tree Terminology
If v is a vertex of a rooted tree other than the root, the parent of v is
the unique vertex u such that there is a directed edge from u to v.
When u is a parent of v, v is called a child of u. Vertices with the
same parent are called siblings.
Parent of g: a
Children of g: h,i,j
Sibling: b, f
29
Rooted Tree Terminology
The ancestors of a vertex are the vertices on the path from the root
to this vertex, excluding the vertex itself and including the root.
The descendants of a vertex v are those vertices that have v as an
ancestor.
Ancestor j: g, a
descendant j: l, m
30
Rooted Tree Terminology
A vertex of a rooted tree with no children is called a leaf. Vertices
that have children are called internal vertices.
Leafs: d, e, k, l, m
Examples of internal nodes: b, g, h
31
Rooted Tree Terminology
If a is a vertex in a tree, the subtree with a as its root is the
subgraph of the tree consisting of a and its descendants and all
edges incident to these descendants.
32
M-ary Tree
Definition: A rooted tree is called an m-ary tree if every internal
vertex has no more than m children. The tree is called a full m-ary
tree if every internal vertex has exactly m children. An m-ary tree
with m = 2 is called a binary tree.
33
Binary Tree
A binary tree is an ordered rooted where each internal
vertex has at most two children. If an internal vertex of a binary
tree has two children, the first is called the left child and the second
the right child. The tree rooted at the left child of a vertex is called
the left subtree of this vertex, and the tree rooted at the right child
of a vertex is called the right subtree of this vertex.
34
Review Graph
determine whether the given graph has an
Euler circuit.
35
Review Graph
determine whether the given graph has a
Hamilton circuit. If it does, find such a circuit.
36
37
38
Thank You
39