Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 79

Mathematical Concepts For Computing

AQ010-3-1 (Version E)

GRAPHS AND TREES


TOPIC LEARNING OUTCOMES
At the end of this topic, You should be able to
• Understand the basic concepts of Graphs.
• Find the degree of a vertex.
• Construct simple undirect graph using handshaking theorem.
• Construct paths and circuits.
• Draw a planar graph.
• Find the shortest path.
• Use graph coloring to find the minimum number of colors.
• Understand the tree terminology.
• Understand the different tree traversals.
• Construct a spanning tree.

AQ010-3-1-MCFC Graphs and Trees SLIDE 2


Contents & Structure
 Introduction
 Definition
 Degree of a Vertex
 Graphs & Representations
 Paths & Circuits
 Shortest path
 Graph coloring
 Planar Graph
 Tree terminology
 Tree traversals
 Spanning tree

AQ010-3-1-MCFC Graphs and Trees SLIDE 3


Graph
General meaning in everyday math:
• A plot or chart of numerical data using a coordinate system.

Technical meaning in discrete mathematics:


• A particular class of discrete structures (to be defined) that is useful for representing
relations and has a convenient webby-looking graphical representation.

AQ010-3-1-MCFC Graphs and Trees SLIDE 4


Application of Graphs
• Social networks
– A friendship graph: two people are connected if they are Facebook friends.
• Communications networks
• Information networks
– In a web graph, web pages are represented by vertices and links are represented
by directed edges.
• Transportation networks

AQ010-3-1-MCFC Graphs and Trees SLIDE 5


Graphs
A graph G = (V, E) consists of V, a nonempty set of vertices (or nodes), and E, a
set of edges. Each edge has either one or two vertices associated with it, called its
endpoints. An edge is said to connect its endpoints.

G=(V, E), where


v1 V={v1,v2,…, v7}
v5
E={{v1,v2}, {v1,v3}, {v2,v3}
v3 v4 {v3,v4}, {v4,v5}, {v4,v6}
v6
{v4,v7}, {v5,v6}, {v6,v7}}
v2 v7

AQ010-3-1-MCFC Graphs and Trees SLIDE 7


Simple graph
A graph in which each edge connects two different vertices and where no two
edges connect the same pair of vertices is called a simple graph.

Example: Now suppose that a network is made up of data centers and communication
links between computers. We can represent the location of each data center by a point
and each communications link by a line segment, as shown in Figure 1.

AQ010-3-1-MCFC Graphs and Trees SLIDE 8


Multigraph
Graphs that may have multiple edges connecting the same vertices are
called multigraph.

AQ010-3-1-MCFC Graphs and Trees SLIDE 9


Pseudograph
Graphs that may include loops, and possibly multiple edges connecting the
same pair of vertices are called pseudographs.

(a loop: )

AQ010-3-1-MCFC Graphs and Trees SLIDE 10


Directed graph
A directed graphs (or diagraph) (V, E) consists of non empty set of vertices
V and a set of directed edges (or arcs) E. Each directed edge is associated
with an ordered pair of vertices. The directed edge associated with the
ordered pair (u, v) is said to start at u and end at v.

Simple directed graphs: When a directed graph has no loops and no


multiple directed edges, it is called a simple directed graph.

u v The two edges (u,v),(u,v) are


multiedges.
The two edges (u,v), (v,u) are not
u v multiedges.

AQ010-3-1-MCFC Graphs and Trees SLIDE 11


Simple directed graph

AQ010-3-1-MCFC Graphs and Trees SLIDE 12


Directed graph
Directed multigraphs : Directed graph that may have multiples directed
edges from a vertex to a second(possibly the same) vertex to model
networks.

AQ010-3-1-MCFC Graphs and Trees SLIDE 13


Graph Terminology
• Two vertices u and v in a undirected graph G are called adjacent (or neighbors) in G
if u and v are endpoints of an edge of G.
• If e is associated with {u, v}, the edge e is called incident with the vertices u and v.

Note : adjacent: a vertex connected to a vertex


incident: a vertex connected to an edge
• The degree of a vertex v, denoted by deg(v),in an undirected graph is the number of
edges incident with it, except that a loop at a vertex contributes twice to the degree of
that vertex.

(Note : A loop adds 2 to the degree.)


AQ010-3-1-MCFC Graphs and Trees SLIDE 15
Degree- Undirected graph
Example 1: What are the degrees of the vertices in the graph H ?

a b Sol : deg(a)=4
c
deg(b)=6
deg(c)=1
deg(d)=5
e d f
deg(e)=6
H deg(f)=0

Note: A vertex of degree 0 is called isolated.

AQ010-3-1-MCFC Graphs and Trees SLIDE 16


Degree - Directed Graph
• in-degree of a vertex v, deg-(v) - the number of edges with v as their
terminal vertex.
• out-degree of v, deg+(v) - the number of edges with v as their initial
vertex.
• A loop at a vertex contributes 1 to both the in-degree and the out-
degree of this vertex.
• Let G=(V, E) be a graph with directed edges. Then

AQ010-3-1-MCFC Graphs and Trees SLIDE 17


In-degree & Out-degree

Example 2: Find the in-degree and out-degree of each vertex in the graph
with directed edges shown below.

In –degree Out–degree

AQ010-3-1-MCFC Graphs and Trees SLIDE 18


The Handshaking Theorem

Let G = (V, E) be an undirected graph with e edges (i.e., |E| = e). Then

 deg(v)  2e
vV

Example 3:
a b c
The graph H has 11 edges, and
 deg(v)  22
vV

e d f
H
AQ010-3-1-MCFC Graphs and Trees SLIDE 19
The Handshaking Theorem (Cont.…)

Example 4: How many edges are there in a graph with 10 vertices each of
degree six?
Sol :10  6 = 2e  e=30

Example 5: How many edges are there in a graph with 5 vertices each of
degree 3?
Sol :5  3 = 2e  e=7.5 Graph doesn’t exist.

Example 6: Draw a simple undirected graph whose degree sequence is


(a) (1, 1, 2, 2, 4) (b) (0, 0, 1, 1) (c) (1, 2, 3, 4, 5)

AQ010-3-1-MCFC Graphs and Trees SLIDE 20


Graphs Representation
• There are several ways to represent graphs.
• Adjacency list – specify the vertices that are adjacent to each vertex of the graph.
• Adjacency Matrices – the n × n zero-one matrix with
 1 as its (i, j)th entry when vi and vj are adjacent.
 0 as its (i, j)th entry when vi and vj are not adjacent.
• G=(V, E) : simple graph, V={v1,v2,…,vn}. A matrix A is called the adjacency
matrix of G if A=[aij]nn , where
aij = 1, if {vi,vj}E,
0, otherwise.

AQ010-3-1-MCFC Graphs and Trees SLIDE 21


Representing Graphs – Adjacency List

Example 7: Use adjacency lists to describe the simple graph given below.

Sol : Vertex Adjacent Vertices


b a b,c,e
b a
a c
c a,d,e
d c,e
e d
e a,c,d

AQ010-3-1-MCFC Graphs and Trees SLIDE 22


Representing Graphs – Adjacency List
Example 8:

b
Initial Terminal vertices
c vertex
a
a b,c,d,e
b b,d
c a,c,e
d -
e d e b,c,d

AQ010-3-1-MCFC Graphs and Trees SLIDE 23


Representing Graphs – Adjacency Matrix

Example 9: Use adjacency matrix to describe the simple graph given


below.

a a b c d
b a 0
1 1 1
1 0 1 1
b
A1   
c 1 1 0 0
c d  
d 1 1 0 0

Note:
1.There are n! different adjacency matrices for a graph with n vertices.
2.The adjacency matrix of an undirected graph is symmetric.

AQ010-3-1-MCFC Graphs and Trees SLIDE 24


Representing Graphs – Adjacency Matrix
Example 10. (Pseudograph)
a b c d
a b a 0 3 0 2
b 3 0 1 1 
A 
c 0 1 1 2
 
d
c
d 2 1 2 0

If A=[aij] is the adjacency matrix for the directed graph, then

1 , if
vi vj
aij =
0 , otherwise
AQ010-3-1-MCFC Graphs and Trees SLIDE 25
Graph Representation

Example 11: Use adjacency list and adjacency matrix to represent the graph:

a b c

e d

AQ010-3-1-MCFC Graphs and Trees SLIDE 26


Paths and Circuits

• A path is a sequence of edges that begins at a vertex of a graph and travels from
vertex to vertex along edges of the graph.
• As the path travels along its edges, it visits the vertices along this path, that is, the
endpoints of these edges.
• The path is a circuit if it begins and ends at the same vertex.

AQ010-3-1-MCFC Graphs and Trees SLIDE 27


Euler Paths and Circuits

• An Euler circuit in a graph G is a simple circuit containing every edge of G.


• An Euler path in G is a simple path containing every edge of G.
• A connected multigraph with at least two vertices has an Euler circuit if and only if
each of its vertices has even degree.
• A connected multigraph has an Euler path (but not an Euler circuit) if and only if it
has exactly 2 vertices of odd degree.

AQ010-3-1-MCFC Graphs and Trees SLIDE 28


Konigsberg- in days past

Is it possible to start at some


location in the town, travel
across all the bridges once
without crossing any bridge
twice, and return to the
starting point ?
c

a d

b
AQ010-3-1-MCFC Graphs and Trees SLIDE 29
Euler Paths and Circuits

Example 12: Which of the following graphs has an Euler circuit?

a b a b a b

e e

d c d c c d e

yes no no, but has Euler path


(a, e, c, d, e, b, a) (a, c, d, a, b, d,, e, b)
AQ010-3-1-MCFC Graphs and Trees SLIDE 30
Exercise

Find the
a) Degree
b) Adjacency List
c) Adjacency Matrix
d) Euler Circuit
e) Euler Path

AQ010-3-1-MCFC Graphs and Trees SLIDE 31


Hamilton Paths and Circuits
• A Hamilton path is a path that traverses each vertex in a graph G exactly once.
• A Hamilton circuit is a circuit that traverses each vertex in G exactly once.

Example 13: Which of the following graphs have a Hamilton


circuit or a Hamilton path?
a b g
a b a b
G1 G2
e c
d c d c e f
d G3
Hamilton circuit: G1 Hamilton path: G2
AQ010-3-1-MCFC Graphs and Trees SLIDE 32
Hamilton Circuits

Dodecahedron puzzle and it equivalent graph

Is there a circuit in this graph that passes through each vertex


exactly once?
AQ010-3-1-MCFC Graphs and Trees SLIDE 33
Hamilton Circuits

Yes; this is a circuit that passes through each vertex exactly once.

AQ010-3-1-MCFC Graphs and Trees SLIDE 34


Hamilton circuit- properties

If a graph G has a Hamilton circuit, then G has a subgraph H with the following
properties:
1. H contains every vertex of G.
2. H is connected.
3. H has the same number of edges as vertices.
4. Every vertex of H has degree 2.

Articulation point: A vertex in an undirected connected graph is an


articulation point (or cut vertex) iff removing it (and edges through it)
disconnects the graph.

AQ010-3-1-MCFC Graphs and Trees SLIDE 35


Hamilton circuit
Example 14: Which of the following graphs have a Hamilton circuit?

Hamilton circuit Exists

AQ010-3-1-MCFC Graphs and Trees SLIDE 36


Hamilton circuit
Example 14: Which of the following graphs have a Hamilton circuit?

Hamilton circuit doesn’t exist because


the graph has Articulation vertex “c”.

AQ010-3-1-MCFC Graphs and Trees SLIDE 37


Hamilton circuit
Example 14: Which of the following graphs have a Hamilton circuit?

Hamilton circuit doesn’t exist because


the graph has Articulation vertex “e”.

AQ010-3-1-MCFC Graphs and Trees SLIDE 38


Activity

Find the Hamilton circuit.

AQ010-3-1-MCFC Graphs and Trees SLIDE 39


Weighted Graphs
• Graphs that have a number assigned to each edge are called weighted graphs.
• Many problems can be modeled using graphs with weights assigned to their
edges.
Example: Weighted Graphs Modeling an Airline system Consider how an airline
system can be modeled. We set up the basic graph model by representing cities by
vertices and flights by edges.

DISTANCE: Problems involving


distances can be modeled by assigning
distances between cities to the edges.

AQ010-3-1-MCFC Graphs and Trees SLIDE 40


Weighted Graphs

TIME: Problems involving flight time can


be modeled by assigning flight times to
edges.

FARE: Problems involving fares can be


modeled by assigning fares to edges.

AQ010-3-1-MCFC Graphs and Trees SLIDE 41


Weighted Simple Graphs

Example 15: What is the length of a shortest


path between a and z in the weighted graph
shown in Figure ?

Answer:
The shortest path is : a-d-e-z and the length of the shortest path from a to z is 6
(2+3+1).

AQ010-3-1-MCFC Graphs and Trees SLIDE 42


Example of Hamilton Circuit

Travelling Salesman Problem: A Hamilton circuit or path may be used to solve


practical problems that require visiting “vertices”, such as:
– road intersections
– pipeline crossings
– communication network nodes

A classic example is the Travelling Salesman Problem finding a Hamilton circuit in a


complete graph such that the total weight of its edges is minimal.

AQ010-3-1-MCFC Graphs and Trees SLIDE 43


Travelling Salesman Problem
Example 16:
For example, suppose that the salesman
wants to visit Detroit, Toledo, Saginaw,
Grand Rapids, and Kalamazoo. In which
order should he visit these cities to travel the
minimum total distance?

AQ010-3-1-MCFC Graphs and Trees SLIDE 44


Travelling Salesman Problem-Solution

• To solve this problem we can assume the salesman starts in Detroit (because this must
be part of the circuit) and examine all possible ways for him to visit the other four
cities and then return to Detroit (starting elsewhere will produce the same circuits).
• There are a total of 24 such circuits, but because we travel the same distance when we
travel a circuit in reverse order, we need only consider 12 different circuits to find the
minimum total distance he must travel.
• We list these 12 different circuits and the total distance traveled for each circuit.
• As can be seen from the list, the minimum total distance of 458 miles is traveled using
the circuit Detroit-Toledo-Kalamazoo-Grand Rapids-Saginaw-Detroit (or its reverse).

AQ010-3-1-MCFC Graphs and Trees SLIDE 45


AQ010-3-1-MCFC Graphs and Trees SLIDE 46
Planar graph
• In graph theory, a planar graph is a graph that can be embedded in the plane,
i.e., it can be drawn on the plane in such a way that its edges intersect only at
their endpoints. In other words, it can be drawn in such a way that no edges cross
each other.
Examples of planner graph:

AQ010-3-1-MCFC Graphs and Trees SLIDE 47


Nonplanar graph
• A graph is said to be non-planar if it cannot be drawn in a plane so that no edge
cross.
• These graphs cannot be drawn in a plane so that no edges cross hence they are
non-planar graphs.
Examples of non-planner graph:

AQ010-3-1-MCFC Graphs and Trees SLIDE 48


Graph Coloring
• A graph coloring is an assignment of labels, called colors, to the vertices of
a graph such that no two adjacent vertices share the same color.
• The chromatic number of a graph is denoted by (G). (Here is the Greek
letter chi.) is the minimal number of colors for which such an assignment is
possible.
• Other types of colorings on graphs also exist, most notably edge colorings that
may be subject to various constraints.

AQ010-3-1-MCFC Graphs and Trees SLIDE 49


THE FOUR-COLOR THEOREM
Theorem: The chromatic number of a planar graph is no greater than four.
• Note that the Four Color Theorem applies only to planar graphs. Non-planar
graphs can have arbitrarily large chromatic numbers

Example 18: What are the chromatic numbers of the graph G shown in
below Figure? Solution

AQ010-3-1-MCFC Graphs and Trees SLIDE 50


Graph Coloring - Explanation
• The chromatic number of G is at least three, because the vertices a, b, and c must
be assigned different colors.
• To see if G can be colored with three colors, assign red to a, blue to b, and green to
c.
• Then, d can (and must) be colored red because it is adjacent to b and c.
• Furthermore, e can (and must) be colored green because it is adjacent only to
vertices colored red and blue, and f can (and must) be colored blue because it is
adjacent only to vertices colored red and green.
• Finally, g can (and must) be colored red because it is adjacent only to vertices
colored blue and green. This produces a coloring of G using exactly three colors.
• Hence, G has a chromatic number equal to 3.

AQ010-3-1-MCFC Graphs and Trees SLIDE 51


Graph Coloring

Example 19: What are the chromatic numbers of the graph H shown in below
Figure?
Solution

AQ010-3-1-MCFC Graphs and Trees SLIDE 52


Applications of Graph Coloring

Graph coloring has a variety of applications to problems involving scheduling and


assignments.
1. Scheduling Final Exams: How can the final exams at a university be
scheduled so that no student has two exams at the same time?
For instance, suppose there are seven finals to be scheduled. Suppose the courses
are numbered I through 7. Suppose that the following pairs of courses have
common students: I and 2, I and 3, I and 4, I and 7, 2 and 3, 2 and 4, 2 and 5, 2 and
7,3 and 4,3 and 6, 3 and 7, 4 and 5, 4 and 6, 5 and 6, 5 and 7, and 6 and 7.

AQ010-3-1-MCFC Graphs and Trees SLIDE 53


In Figure , the graph
associated with this set of
classes is shown.

Because the chromatic


number of this graph is 4
four time slots are needed.
A coloring of the graph
using four colors and the
associated schedule are
shown in Figure.

AQ010-3-1-MCFC Graphs and Trees SLIDE 54


Applications of Graph Coloring

Some other applications:


1. Mobile radio frequency assignment
2. Sudoku
3. Register allocation
4. Map coloring
5. Clustering
6. Data mining
7. Image capturing
8. Process scheduling

AQ010-3-1-MCFC Graphs and Trees SLIDE 55


Trees
• A connected graph that contains no simple circuits is called a tree. Since a tree
cannot have a circuit, a tree cannot contain multiple edges or loops. Therefore, any
tree must be a simple graph.
• Tree are used to construct efficient algorithms for locating items in a list.
• Trees can be used in algorithms, such as Huffman coding, that construct efficient
codes saving cost in data transmission and storage.
• Trees can be used to model procedures carried out using a sequence of decisions and
these models can help determine the computational complexity of algorithms based
on a sequence of decisions, such as sorting algorithms.

AQ010-3-1-MCFC Graphs and Trees SLIDE 56


Trees

Theorem: A undirected graph is a tree if and only if there is a unique simple path
between any of its vertices.
Example 1. Which of the graphs are trees?

Sol: G1, G2
AQ010-3-1-MCFC Graphs and Trees SLIDE 57
Tree Terminology
• If v is a vertex of tree T 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 the parent of v, v is called the child of u.
• If two vertices share the same parent, then they are called siblings.
• The ancestors of a vertex other than the root are the vertices in 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.
• A vertex with no children is called a leaf.
• Vertices with children are called internal vertices.

AQ010-3-1-MCFC Graphs and Trees SLIDE 58


Example

Root a

b c d

e f g h

i j k l m

AQ010-3-1-MCFC Graphs and Trees SLIDE 59


Example

Siblings b c d

e f g h

i j k l m

AQ010-3-1-MCFC Graphs and Trees SLIDE 60


Example

Leaves a

b c d

e f g h

i j k l m

AQ010-3-1-MCFC Graphs and Trees SLIDE 61


Example

a
Internal vertices

b c d

e f g h

i j k l m

AQ010-3-1-MCFC Graphs and Trees SLIDE 62


Tree Terminology (Cont.)

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.
a

Subtree at b Subtree at d
b c d

e f g h

i j k l m
AQ010-3-1-MCFC Graphs and Trees SLIDE 63
Tree Traversal
• Ordered trees are often used to restore data/info.
• Tree traversal is a procedure for systematically visiting each vertex of an
ordered rooted tree to access data.
• Tree traversal algorithm
– Preorder, inorder and postorder traversal

AQ010-3-1-MCFC Graphs and Trees SLIDE 64


Preorder Traversal
• Let T be an ordered rooted tree with root r.
– If T consists only of r, then r is the preorder traversal of T.
– If T1, T2, …, Tn are subtrees at r from left to right in T, then the preorder
traversal begins by visiting r, continues by traversing T1 in preorder, then T2
in preorder, and so on until Tn is traversed in preorder.

r STEP 1
Visit r TIPS
Preorder Traversal:
Visit root, visit
subtrees left to right
T1 T2 … Tn

STEP 2 STEP 3 STEP n+1


Visit T1 in preorder Visit T2 in preorder Visit Tn in preorder
AQ010-3-1-MCFC Graphs and Trees SLIDE 65
EXAMPLE: Preorder Traversal
a a b e f c d g h i
T b d
c
• • • • • • •
e f k m
g h i j l
j k m
l n ITERATION 2
o p
n
o p a b e j k f c d g l m h i
• • • • • • • • • • • •
a b c d
• • n ITERATION 3
o p
e f
g h i
k ab e j k n opf c dgl m h i
j m
l •• • ••• ••• • ••• • • •
ITERATION 4
n
o p
ITERATION 1
The preorder traversal of T
AQ010-3-1-MCFC Graphs and Trees SLIDE 66
Inorder Traversal
• Let T be an ordered rooted tree with root r.
– If T consists only of r, then r is the inorder traversal of T.
– If T1, T2, …, Tn are subtrees at r from left to right in T, then the inorder
traversal begins by traversing T1 in inorder, then visiting r, continues
by traversing T2 in inorder, and so on until Tn is traversed in inorder.

r STEP 2
Visit r TIPS
Inorder Traversal:
Visit leftmost
subtree, Visit root,
T1 T2 … Tn Visit other subtrees
left to right.
STEP 1 STEP 3 STEP n+1
Visit T1 in inorder Visit T2 in inorder Visit Tn in inorder
AQ010-3-1-MCFC Graphs and Trees SLIDE 67
EXAMPLE: Inorder Traversal
a e b f a c g d h i
T b d
c
• • • • • • •
e f k m
g h i j l
j k m
l n ITERATION 2
o p
n
o p j e k b f a c l g m d h i
• • • • • •• • • • • •
b a c d
• • n ITERATION 3
o p
e f
g h i
k j e n k opb f ac l g m d h i
j m
l •• • •••• ••••• • • • •
ITERATION 4
n
o p
ITERATION 1
The inorder traversal of T
AQ010-3-1-MCFC Graphs and Trees SLIDE 68
Postorder Traversal
• Let T be an ordered rooted tree with root r.
– If T consists only of r, then r is the postorder traversal of T.
– If T1, T2, …, Tn are subtrees at r from left to right in T, then the preorder
traversal begins by traversing T1 in postorder, then T2 in postorder, and so
on until Tn is traversed in postorder and ends by visiting r.

r STEP n+1
Visit r TIPS
Postorder Traversal:
Visit subtrees left to
right, Visit root.
T1 T2 … Tn

STEP 1 STEP 2 STEP n


Visit T1 in postorder Visit T2 in postorder Visit Tn in postorder
AQ010-3-1-MCFC Graphs and Trees SLIDE 69
EXAMPLE: Postorder Traversal
a e f b c g h i d a
T b d
c
• • • • • • •
e f k m
g h i j l
j k m
l n ITERATION 2
o p
n
o p j f b c l m g h i da
k e
• • • • • • • • • •••
b c d a
• • n o p
ITERATION 3

e f
g h i
k j n o pk e f bc l m g hi d a
j m
l •• • ••• ••• •• • •• • •
ITERATION 4
n
o p
ITERATION 1
The postorder traversal of T
AQ010-3-1-MCFC Graphs and Trees SLIDE 70
Summary

AQ010-3-1-MCFC Graphs and Trees SLIDE 71


Exercise

In which order does


a) preorder traversal
b) inorder traversal
c) postorder traversal
visit the vertices in the ordered
rooted tree?

AQ010-3-1-MCFC Graphs and Trees SLIDE 72


Spanning Tree
Example: Consider the system of roads in Maine represented by the simple graph
shown in Figure (a). The only way the roads can be kept open in the winter is by
frequently plowing them. The highway department wants to plow the fewest roads so
that there will always be cleared roads connecting any two towns. How can this be
done?

AQ010-3-1-MCFC Graphs and Trees SLIDE 73


Spanning Tree
At least five roads must be plowed to ensure that there is a path between any two
towns. Figure (b) shows one such set of roads. Note that the subgraph representing
these roads is a tree, because it is connected and contains six vertices and five edges.
This problem was solved with a connected sub graph with the minimum number of
edges containing all vertices of the original simple graph.

AQ010-3-1-MCFC Graphs and Trees SLIDE 74


AQ010-3-1-MCFC Graphs and Trees SLIDE 75
Spanning Tree
Theorem: Let G be a simple graph. A spanning tree of G is a sub graph of G that
is a tree containing every vertex of G.
• A simple graph with a spanning tree must be connected, because there is a
path in the spanning tree between any two vertices.
• The converse is also true; that is, every connected simple graph has a
spanning tree
Example: Find a spanning tree of the simple graph G shown in Figure.

AQ010-3-1-MCFC Graphs and Trees SLIDE 76


Spanning Tree

The sequence of edge removals used to produce the spanning tree is


illustrated in Figure below.

Producing a spanning tree for G by removing edges that form simple


circuits

AQ010-3-1-MCFC Graphs and Trees SLIDE 77


Spanning Tree of G

AQ010-3-1-MCFC Graphs and Trees SLIDE 78


Applications of Spanning Tree
• IP Multicasting: Spanning trees play an important role in multicasting over Internet
Protocol (IP) networks.
• To send data from a source computer to multiple receiving computers, each of which is a sub
network, data could be sent separately to each computer.
• This type of networking, called unicasting, is inefficient, because many copies of the same
data are transmitted over the network.
• To make the transmission of data to multiple receiving computers more efficient, IP
multicasting is used.
• With IP multicasting, a computer sends a single copy of data over the network, and as data
reaches intermediate routers, the data are forwarded to one or more other routers so that
ultimately all receiving computers in their various sub networks receive these data.

AQ010-3-1-MCFC Graphs and Trees SLIDE 79


Applications of Spanning Tree
• For data to reach receiving computers as quickly as possible, there should be no loops
(which in graph theory terminology are circuits or cycles) in the path that data take
through the network.
• That is, once data have reached a particular router, data should never return to this
router.
• To avoid loops, the multicast routers use network algorithms to construct a spanning
tree in the graph that has the multicast source, the routers, and the sub networks
containing receiving computers as vertices, with edges representing the links between
computers and/or routers.
• The root of this spanning tree is the multicast source. The sub networks containing
receiving computers are leaves of the tree.

AQ010-3-1-MCFC Graphs and Trees SLIDE 80


Summary / Recap of Main Points

• Introduction
• Definition
• Degree of a Vertex
• Graphs & Representations
• Paths & Circuits
• Shortest path
• Graph coloring
• Planar Graph
• Tree terminology
• Tree traversals
• Spanning tree

AQ010-3-1-MCFC Graphs and Trees SLIDE 81

You might also like