Discrete Math - Graph - Tree
Discrete Math - Graph - Tree
Lecture 17-18
1
Graph
– Computer networks
– Social networks
– Communications networks
– Information networks
– Software design
– Transportation networks
– Biological networks
2
Graph
Example
3
Terminology
In a simple graph each edge connects two different
vertices and no two edges connect the same pair of
vertices.
Remark:
– Graphs where the end points of an edge are not ordered are said
to be undirected graphs.
5
Directed graph
A simple directed graph has no loops and no multiple edges.
Example:
Example:
• multiplicity of (a,b) is ?
• and the multiplicity of (b,c) is ?
6
Directed graph
A simple directed graph has no loops and no multiple edges.
Example:
Example:
• multiplicity of (a,b) is ? 1
• and the multiplicity of (b,c) is ? 2
7
Undirected graph
Definition 1. Two vertices u, v in an undirected graph G are
called adjacent (or neighbors) in G if there is an edge e between u and
v. Such an edge e is called incident with the vertices u and v
and e is said to connect u and v.
8
Undirected graph
Example: What are the degrees and neighborhoods of the vertices in
the graphs G?
Solution:
G: deg(a) = 2,
deg(b) = deg(c) = deg(f ) = 4,
deg(d ) = 1,
deg(e) = 3,
deg(g) = 0.
N(a) = {b, f }, N(b) = {a, c, e, f }, N(c) = {b, d, e, f },
N(d) = {c}, N(e) = {b, c , f }, N(f) = {a, b, c, e}, N(g) = Ø . 9
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}.
10
Undirected graph
Theorem 1 : If G = (V,E) is an undirected graph with m edges, then
2m deg(v)
Proof: vV
11
Undirected graph
Theorem 2: An undirected graph has an even number of vertices of
odd degree.
12
Directed graph
Definition: An directed graph G = (V, E) consists of V, a
nonempty set of vertices (or nodes), and E, a set of directed edges
or arcs. Each edge is an ordered pair of vertices. The directed
edge (u,v) is said to start at u and end at v.
13
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
14
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
15
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
16
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
17
Directed graph
Theorem: Let G = (V, E) be a graph with directed edges. Then:
Proof:
The first sum counts the number of outgoing edges over all vertices
and the second sum counts the number of incoming edges over all
vertices. It follows that both sums equal the number of edges in the
graph.
18
Complete graph
A complete graph on n vertices, denoted by Kn, is the simple
graph that contains exactly one edge between each pair of distinct
vertices.
19
A Cycle
A cycle Cn for n ≥ 3 consists of n vertices v1, v2 ,⋯ , vn, and edges
{v1, v2}, {v2, v3} ,⋯ , {vn-1, vn}, {vn, v1}.
20
N-dimensional hypercube
An n-dimensional hypercube, or n-cube, Qn, is a graph with 2n
vertices representing all bit strings of length n, where there is an
edge between two vertices that differ in exactly one bit position.
21
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.
22
Bipartite Graph
Example: Show that C6 is bipartite.
23
Bipartite Graph
Example: Show that C6 is bipartite.
24
Bipartite Graph
Example: Show that C3 is not bipartite.
25
Bipartite Graph
Example: Show that C3 is not bipartite.
26
Complete Bipartite Graph
Definition: A complete bipartite graph Km,n is a graph that
has its vertex set partitioned into two subsets V1 of size m
and V2 of size n such that there is an edge from every
vertex in V1 to every vertex in V2.
27
Subgraph
Definition: A subgraph of a graph G = (V,E) is a graph
(W,F), where W ⊂ V and F ⊂ E. A subgraph H of G is a
proper subgraph of G if H ≠ G.
28
Subgraph
Definition: Let G = (V, E) be a simple graph. The subgraph
induced by a subset W of the vertex set V is the graph
(W,F), where the edge set F contains an edge in E if and
only if both endpoints are in W.
29
Union of Graph
Definition: The union of two simple graphs G1 = (V1, E1) and
G2 = (V2, E2) is the simple graph with vertex set V1 ⋃ V2 and
edge set E1 ⋃ E2. The union of G1 and G2 is denoted by G1
⋃ G2.
Example:
30
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, c, d
31
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
32
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
33
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 34
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.
35
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.
Example:
37
Tree
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:
38
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:
39
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.
40
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
41
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
42
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
43
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.
44
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.
45
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.
46
Thank You
47