0% found this document useful (0 votes)
987 views

GTU Graph Theory

The document defines various graph theory concepts. It begins by introducing graph theory and its applications in computer science. It then defines graphs, nodes, edges, adjacent nodes, incident edges, loops, parallel edges, directed and undirected edges. It also defines directed graphs, undirected graphs, mixed graphs, multigraphs, simple graphs, weighted graphs, isolated nodes, and null graphs. Examples are provided to illustrate these concepts. The document also discusses isomorphic graphs.

Uploaded by

Avirup Ray
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
987 views

GTU Graph Theory

The document defines various graph theory concepts. It begins by introducing graph theory and its applications in computer science. It then defines graphs, nodes, edges, adjacent nodes, incident edges, loops, parallel edges, directed and undirected edges. It also defines directed graphs, undirected graphs, mixed graphs, multigraphs, simple graphs, weighted graphs, isolated nodes, and null graphs. Examples are provided to illustrate these concepts. The document also discusses isomorphic graphs.

Uploaded by

Avirup Ray
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

U n i t - 5 ≻≻ G r a p h T h e o r y

❖ INTRODUCTION
✓ Graph theory plays an important role in several areas of computer science such as switching
theory and logical design, artificial intelligence, formal languages, computer graphics,
operating systems, compiler writing, information organization and retrieval.
❖ GRAPH
✓ A graph G =< V, E, ∅ > consists of a nonempty set V called the set of nodes (points, vertices)
of the graph, E is said to be the set of edges of the graph and ∅ is a mapping from the set of
edges E to a set of ordered or unordered pairs of elements of V.
✓ 𝐕 = 𝐕ሺ𝐆ሻ = ሼv1 , v2 , v3 , … ሽ = The set of nodes(vertices/points/dots/junctions).
✓ 𝐄 = 𝐄ሺ𝐆ሻ = ሼe1 , e2 , e3 , … ሽ = The set of edges(branch/line/arc).
✓ The elements of V are called nodes/vertices of a graph G and the elements of E are called
edges of a graph G.

𝒗𝒊 𝒆𝒌 𝒗𝒋
v v v
NOTE:
✓ Throughout, we shall assume that the sets V and E of a graph G are finite.
✓ Any edge e can be made by one OR two nodes ሺu, uሻ OR ሺu, vሻ respectively.

𝒆
𝒆
𝒖 𝒗
❖ ADJACENT NODES 𝒖

✓ If two nodes u and v are joined by an edge e then u and v are said to be adjacent nodes.
❖ INCIDENT EDGE
✓ An edge e ∈ E (directed/undirected) which joins the nodes u and v is said to be incident to
the nodes u and v.

𝑢 𝑒 𝑣
v v

❖ LOOP(SLING)
✓ An edge e of a graph G that joins a node u to itself is called a loop. A loop is 𝑒
an edge e = ሺu, uሻ.
𝑢

❖ PARALLEL EDGES
𝑒1
✓ If two nodes of a graph are joined by more than one edge then 𝑣
𝑢 𝑒2
these edges are called parallel edges/multiple edges.
𝑒3

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 1


U n i t - 5 ≻≻ G r a p h T h e o r y
❖ DIRECTED EDGES
✓ In a graph G an edge ‘e’ which is associated with an ordered pair of nodes ‘u’ to ‘v’ is called
directed edge of graph G.
❖ INITIATING NODE AND TERMINATING NODE
✓ Let G = ሺV, Eሻ be a graph and let e ∈ E be a directed edge associated
𝑒
with the order pair < u, v > of the nodes ‘u’ and ‘v’ then the edge ‘e’ is 𝑢 𝑣
said to be initiatingሺoriginatingሻ in the node ‘u’ and
terminatingሺendingሻ in the node ‘v’. The nodes ‘u’ and ‘v’ are called initial node and terminal
node of the edge ‘e’ respectively.
❖ DIRECTED GRAPH/DIGRAPH
✓ A graph in which every edge is directed is called a directed graph(digraph).
𝑣2

𝑣2 𝑒1
𝑒2
𝑒1 𝑒2 𝑒1
𝑣1 𝑒6 𝑣3 𝑣1 𝑣2
𝑒5
𝑣1 𝑣3
𝑒2 𝑒3
𝑒4

𝑣4

❖ UNDIRECTED EDGE
✓ In a graph G an edge ‘e’ which is associated with an unordered pair 𝑒
𝑢 𝑣
ሺu, vሻ of nodes ‘u’ and ‘v’ is called undirected edge of graph G.
❖ UNDIRECTED GRAPH
𝑣7
𝑣2
✓ A graph in which every edge is 𝑣8
undirected is called an 𝑒2 𝑒5

undirected graph. 𝑒1 𝑣5
𝑣3
𝑣1
𝑒3
𝑒7
𝑒6
𝑒4

𝑒8 𝑣6
𝑒9
𝑣4
𝑣9
𝑒10

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 2


U n i t - 5 ≻≻ G r a p h T h e o r y
❖ MIXED GRAPH
✓ If some edges of a graph G are directed and some are
undirected then G is said to be a mixed graph.

❖ DISTINCT EDGES
✓ The two possible edges between a pair of nodes which are opposite
in direction which are known as distinct edges.

❖ MULTI GRAPH
✓ Any graph which contains some parallel edges is called a
multigraph.

❖ SIMPLE GRAPH
✓ A graph which has neither loop nor parallel edges is called a simple
graph.

❖ WEIGHTED GRAPH 𝑣2
✓ A graph in which weighted are assigned to every edge is called
20 10
a weighted graph.

𝑣1 𝑣3
5
❖ ISOLATED NODE
✓ In a graph a node which is not adjacent to any other node is called an isolated node.
❖ NULL GRAPH
✓ A graph containing only isolated nodes is called a null graph.
✓ The set of edges in the null graph is empty.

NOTE:
1
✓ It can happen that two diagrams which look
1 2
entirely different but both may represent the
same graph.
4 3 2 3

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 3


U n i t - 5 ≻≻ G r a p h T h e o r y
❖ METHOD-1: BASIC DEFINITIONS AND RELATED EXAMPLES

H 1 Define with example: graph, nodes and edges.

T 2 Define with example: adjacent nodes, initiating node, terminating node and isolated
node.

T 3 Define with example: incident edges, loop, parallel edges, directed edges, undirected
edges and distinct edges.

H 4 Define with example: directed graph, undirected graph, mixed graph, multi graph,
simple graph, weighted graph and null graph.

C 5 Draw the undirected graph G = ሺV, Eሻ where, V = ሼa, b, c, d, eሽ and E =


ሼe1 , e2 , e3 , e4 , e5 , e6 , e7 ሽ and its incidence relation given as: e1 = ሺa, bሻ, e2 =
ሺa, bሻ, e3 = ሺb, cሻ, e4 = ሺc, dሻ, e5 = ሺb, bሻ, e6 = ሺa, dሻ & e7 = ሺe, dሻ. Discuss the terms
defines in example 1 to 4 for G.

C 6 Draw the directed graph G =< V, E > where, V = ሼa, b, c, d, e, f, gሽ and E =


ሼe1 , e2 , e3 , e4 , e5 , e6 , e7 , e8 ሽ and its incidence relation given as: e1 =< b, a >, e2 =<
d, a >, e3 =< b, c >, e4 =< d, c >, e5 =< c, f >, e6 =< f, f >, e7 =< e, c > & e8 =<
c, e >. Discuss the terms defines in example 1 to 4 for G.

❖ ISOMORPHIC GRAPH
✓ A graph G1 = ሺV1 , E1 ሻ is said to be isomorphic to the graph G2 = ሺV2 , E2 ሻ if there exists a
bijection between the set of nodes V1 and V2 and a bijection between the set of edges E1 and
E2 such that if e is an edge with end nodes u and v in G1 then the corresponding edge e′ has
its end nodes u′ and v ′ in G2 which correspond to u and v respectively. If such pair of
bijections exist then it is called a graph isomorphism and it is denoted by G1 ≅ G2.
✓ According to the definition of isomorphism we note that any two nodes in one graph which
are joined by an edge must have the corresponding nodes in the other graph also joined by
an edge and hence a one to one correspondence exists between the edges as well.

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 4


U n i t - 5 ≻≻ G r a p h T h e o r y
EXAMPLE 1:
4
𝑢3 𝑢4

3
2

𝑢2 𝑢1
1

𝐺1 𝐺2

✓ Here G1 and G2 are isomorphic because of the existence of a mapping 1 → u3 , 2 → u1 , 3 →


u4 & 4 → u2 .
✓ Under this mapping the edges < 1, 3 >, < 1, 2 >, < 2, 4 > & < 3, 4 > are mapped into <
u3 , u4 >, < u3 , u1 >, < u1 , u2 > & < u4 , u2 > which are the only edges of the graph in G2 .
NOTE:
✓ The two graphs which are isomorphic have the same number of nodes and edges but
converse need not be true. i.e., If the two graphs which has same number of nodes and edges
implies both graphs need not be isomorphic.
EXAMPLE 2:

1 𝑣1

3 𝑣3
𝑣2
2

𝐺1 𝐺2

✓ Here g1 and g 2 both has same number of nodes and edges but g1 is not isomorphic to g 2 . I.e.,
G1 ≇ G2 because the edge < 3, 1 >↛< v1 , V3 >.
NOTE:
✓ The concept of isomorphism also defines in undirected graphs with the same definition given
for directed graphs.

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 5


U n i t - 5 ≻≻ G r a p h T h e o r y
EXAMPLE 3:

a
1

5
0 e b
2

4
3
d c

𝐺1 𝐺2

✓ Here G1 and G2 are isomorphic because of the existence of a mapping 1 → a, 2 → d, 3 → b, 4 →


e & 5 → c.
✓ Under this mapping, the edges ሺ1, 3ሻ, ሺ3, 5ሻ, ሺ5, 2ሻ, ሺ2, 4ሻ & ሺ4, 1ሻ are mapped into
ሺa, bሻ, ሺb, cሻ, ሺc, dሻ, ሺd, eሻ, & ሺe, aሻ which are the only edges of the graph in G2 .
❖ ORDER Of A GRAPH
✓ The number of nodes in a graph G is called order of the graph G.
❖ SIZE OF A GRAPH
✓ The number of edges in a graph G is called size of the graph G.
❖ DEGREE OF A NODE
✓ Let G be an undirected graph then the degree of a node v in G is defined as the number of
edges incident on v. It is denoted by dሺvሻ or dG ሺvሻ or deg ሺvሻ.
NOTE:
✓ Self-loop will be counted twice in the degree of corresponding node.
❖ ODD NODE
✓ A node with odd degree is called an odd node.
❖ EVEN NODE
✓ A node with even degree is called an even node.
❖ ISOLATED NODE
✓ A node with degree zero is called isolated node.
❖ PENDANT NODE
✓ A node with degree one is called a pendent node.

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 6


U n i t - 5 ≻≻ G r a p h T h e o r y
EXAMPLE:

𝑣7
𝑣2
𝑣8

𝑣5
𝑣3
𝑣1

𝑣6
𝑣4
𝑣9

✓ Here dሺv1 ሻ = 4, dሺv2 ሻ = 3, dሺv3 ሻ = 1, dሺv4 ሻ = 6, dሺv5 ሻ = 2, dሺv6 ሻ = 1, dሺv7 ሻ = 0, dሺv8 ሻ =


0 & dሺv9 ሻ = 3.
✓ From degree of nodes we conclude that nodes v1 , v4 & v5 are even nodes, nodes v2 , v3 , v6 & v9
are odd nodes, nodes v7 & v8 are isolated nodes and nodes v3 & v6 are pendent nodes.
❖ 𝐇𝐀𝐍𝐃𝐒𝐇𝐀𝐊𝐈𝐍𝐆 𝐓𝐇𝐄𝐎𝐑𝐄𝐌
✓ Any undirected graph G with n nodes v1 , v2 , … , vn and e edges
𝐧

෍ 𝐝ሺ𝐯𝐢 ሻ = 𝟐𝐞.
𝐢=𝟏

✓ In above graph
9

෍ dሺvi ሻ = dሺv1 ሻ + dሺv2 ሻ + dሺv3 ሻ + dሺv4 ሻ + dሺv5 ሻ + dሺv6 ሻ + dሺv7 ሻ + dሺv8 ሻ + dሺv9 ሻ
i=1

= 4 + 3 + 1 + 6 + 2 + 1 + 0 + 0 + 3 = 20 = 2ሺ10ሻ = 2e.
❖ 𝐑𝐄𝐒𝐔𝐋𝐓
✓ In any undirected graph G, number of odd nodes must be even.
✓ In above graph there are 4(even) number of nodes.
❖ INDEGREE
✓ Let G be a directed graph then for any node v in G, the number of edges which have v as their
terminal node is called the indegree of the node v.
OR
✓ In a directed graph G, the number of edges directed towards node v is called indegree of a
node v. It is denoted by d− ሺvሻ.

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 7


U n i t - 5 ≻≻ G r a p h T h e o r y
❖ OUTDEGREE
✓ Let G be a directed graph then for any node u in G, the number of edges which have u as their
initial node is called the outdegree of the node u.
OR
✓ In a directed graph G, the number of edges directed outwards node u is called indegree of a
node u. It is denoted by d+ ሺuሻ.
❖ TOTAL DEGREE OF A NODE
✓ Sum of the indegree and the outdegree of a node v is called total degree of a node v. It is
denoted by dሺ vሻ. i.e., dሺ vሻ = d− ሺvሻ + d+ ሺvሻ.
EXAMPLE: 𝑣2

d+ ሺv1 ሻ = 1, d− ሺv1 ሻ = 1 ⇒ dሺv1 ሻ = 2


d+ ሺv2 ሻ = 2, d− ሺv2 ሻ = 2 ⇒ dሺv2 ሻ = 4
d+ ሺv3 ሻ = 1, d− ሺv3 ሻ = 1 ⇒ dሺv3 ሻ = 2 𝑣1 𝑣3
d+ ሺv4 ሻ = 2, d− ሺv4 ሻ = 2 ⇒ dሺv4 ሻ = 4

NOTE: 𝑣4

✓ The total degree of an isolated node is 0.


✓ The node with degree 1 is known as pendent node.
❖ 𝐑𝐄𝐒𝐔𝐋𝐓
✓ In directed graph G with n nodes v1 , v2 , … , vn and e edges
𝐧 𝐧 𝐧

෍ 𝐝+ ሺ𝐯𝐢 ሻ = ෍ 𝐝− ሺ𝐯𝐢 ሻ = 𝐞 and ෍ 𝐝ሺ𝐯𝐢 ሻ = 𝟐𝐞.


𝐢=𝟏 𝐢=𝟏 𝐢=𝟏

✓ In above example,
4 4 4

෍ d+ ሺvi ሻ = ෍ d− ሺvi ሻ = 6 and ෍ dሺvi ሻ = 12 = 2 times no. of edges .


i=1 i=1 i=1

❖ SUBGRAPHS
✓ Let G and H be two graphs. Then H is said to be a subgraph of G if VሺHሻ ⊆ VሺGሻ & EሺHሻ ⊆ EሺGሻ.
Here G is called super graph of H.

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 8


U n i t - 5 ≻≻ G r a p h T h e o r y
EXAMPLE:

G H
✓ Here H is subgraph of G.
NOTE:
✓ The graph G as well as the null graph obtained from G by deleting all the edges of G are
subgraphs of G. Other subgraphs of G can be obtained by deleting certain nodes and edges of
G.
❖ NODE DELETED SUBGRAPH
✓ The graph obtained by deletion of a node v from a given graph G is called node deleted
subgraph of G. It is denoted by G − ሼvሽ.
❖ EDGE DELETED SUBGRAPH
✓ The graph obtained by deletion of an edge e from a given graph G is called edge deleted
subgraph of G. It is denoted by G − ሼeሽ.
❖ CONVERSE (REVERSAL/DIRECTIONAL DUAL) OF A DIGRAPH
෩ =< V, E
✓ The converse of a digraph G =< V, E > to be a digraph G ෩ > in which the relation E
෩ is
෩ is obtained from G by simply reversing the
the converse of the relation E. The diagram G
෩ is also called the reversal or directional dual of a
directions of the edges in G. The converse G
digraph G.
EXAMPLE:

𝑣2 𝑣2

𝑣1 𝑣3 𝑣1 𝑣3

𝑣4 𝑣4

G 𝐺෨

෩ are converse of each other.


✓ In the above diagram G & G

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 9


U n i t - 5 ≻≻ G r a p h T h e o r y
❖ METHOD-2: PROPERTIES OF GRAPHS

H 1 Define with example: isomorphism of graphs.

C 2 Draw all possible different simple digraphs having three nodes up to isomorphism.
Show that there is only one digraph with no edges, one with one edge, four with two
edges, four with three edges, four with four edges, one with five edges and one with
six edges. Assume that there are no loops.

T 3 Define with example: degree of a node, odd node, even node, pendant node and
isolated node for undirected graph.

T 4 Define with example: indegree, outdegree and total degree for directed graph.

C 5 Show that the sum of indegrees of all the nodes of a simple digraph is equal to the sum
of outdegrees of all its nodes and that this sum is equal to the number of edges of the
graph.

H 6 Define with example: subgraph of a graph and converse of a digraph.

T 7 Consider the following graphs: Determine the degree of each node and verify
Handshaking theorem.

𝑣5 𝑣1

𝑣1 𝑣2
𝑣4 𝑣2 𝑣5
𝑣3

𝑣6 𝑣3

𝑣5 𝑣4
𝑣3 𝑣4
𝑣1 𝑣2

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 10


U n i t - 5 ≻≻ G r a p h T h e o r y

C 8 Check whether the following pair of graphs G & H are isomorphic or not with
description.
(A).

G H

(B).

G H

(C).

G H

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 11


U n i t - 5 ≻≻ G r a p h T h e o r y

C 9 Define node deleted subgraph and edge deleted


𝑣1 𝑒6
subgraph. Also find subgraphs from the given 𝑒1 𝑒7
graph G by deleting (I) node v1 ሺG − ሼv1 ሽሻ & (II) 𝑒8
𝑣2
edge e4 ሺG − ሼe4 ሽሻ. 𝑣5
𝑒2 𝑒5

𝑣3 𝑒3 𝑣4

𝑒4
G

H 10 Define converse of a digraph and find it for given


graph G.

NOTE:
✓ In this method we introduce some additional terminology associated with a simple digraph.
❖ PATH OF A GIVEN GRAPH
✓ Let G = ሺV, Eሻ be a simple digraph. Consider a sequence of edges of G such that the terminal
vertex of any edge in the sequence is the initial vertex of next edge. Such a sequence is called
a path of the graph G.
✓ A path is said to traverse through the nodes appearing in the sequence originating in the
initial node of the first edge and ending in the terminal node of the last edge in the sequence.
❖ LENGTH OF PATH
✓ The number of edges appearing in the sequence of a path is called the length of the path.
❖ SIMPLE PATH (EDGE SIMPLE)
✓ A path in a diagraph in which all the edges are distinct is called a simple path (edge simple).
❖ ELEMENTARY PATH (NODE SIMPLE)
✓ A path in a digraph in which all the nodes through which it traverses are distinct is called an
elementary path (node simple).

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 12


U n i t - 5 ≻≻ G r a p h T h e o r y
NOTE:
✓ Naturally every elementary path of a digraph is also simple.
EXAMPLE:
✓ Paths originating in the node 1 and ending in node 3 2
are 1

P1 = ሺ< 1,2 >, < 2,3 >ሻ


P2 = ሺ< 1,4 >, < 4,3 >ሻ
P3 = ሺ< 1,2 >, < 2,4 >, < 4,3 >ሻ
P4 = ሺ< 1,2 >, < 2,4 >, < 4,1 >, < 1,2 >, < 2,3 >ሻ
P5 = ሺ< 1,2 >, < 2,4 >, < 4,1 >, < 1,4 >, < 4,3 >ሻ
4 3
P6 = ሺ< 1,1 >, < 1,1 >, … , < 1,2 >, < 2,3 >ሻ
✓ The paths P1 , P2 & P3 of the digraph in above figure are elementary. The path P5 is simple but
not elementary.
✓ If there exist a path from u to v then there must be an elementary path from u to v.
❖ CYCLE (CIRCUIT)
✓ A path which originates and ends in the same node is called a cycle (circuit).
EXAMPLE:
✓ The following are some of the cycles in the
given graph:
2
C1 = ሺ< 1,1 >ሻ 1

C2 = ሺ< 1,2 >, < 2,1 >ሻ


C3 = ሺ< 1,2 >, < 2,3 >, < 3,1 >ሻ
C4 = ሺ< 1,4 >, < 4,3 >, < 3,1 >ሻ
C5 = ሺ< 1,4 >, < 4,3 >, < 3,2 >, < 2,1 >ሻ

4 3
❖ SIMPLE CYCLE
✓ A cycle is called simple if its path is simple path. i.e., no edge in the cycle appears more than
once in the path.
❖ ELEMENTARY CYCLE
✓ A cycle is called elementary if it does not traverse through any node more than once.
NOTE:
✓ In a cycle the initial node appears at least twice even if it is an elementary cycle.

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 13


U n i t - 5 ≻≻ G r a p h T h e o r y
✓ Observe that any path which is not elementary contains cycle traversing through those nodes
which appear more than once in the path.
✓ In above graph all the cycles C1 , C2 , C3 , C4 & C5 are simple as well as elementary.
❖ ACYCLIC GRAPH
✓ A simple digraph which does not have any cycles is called acyclic. An acyclic graph does not
have any loop.
❖ REACHABILITY
✓ A node v of a simple digraph is said to be reachable (accessible) from the node u of the same
digraph if there exist a (at least one) path from u to v.
✓ It is clear from the definition that reachability is a binary relation on the set of nodes of a
simple digraph. Reachability is reflexive and transitive relation. Reachability is not
necessarily symmetric nor it is antisymmetric.
❖ GEODESIC
✓ If a node v is a reachable from the node u then a path of minimum length from u to v is called
a geodesic.
❖ DISTANCE
✓ The length of a geodesic from the node u to the node v is called the distance and it is denoted
by d < u, v >.
❖ DIAMETER
✓ The diameter of a simple digraph G =< V, E > is given by δ, where δ = max dሺu, vሻ.
u,v∈V

NOTE:
✓ It is assumed that d < u, u > = 0 for any node u.
❖ PROPERTIES OF REACHABILITY
✓ If v is reachable from u then d < u, v > satisfies the following properties:
1. d < u, v > ≥ 0.
2. d < u, u ≥ 0.
3. d < u, v > +d < v, w > ≥ d < u, w >. (Triangle inequality)
NOTE:
✓ If v is not reachable from u then it is customary to write d < u, v >= ∞.
✓ If v is reachable from u and u is reachable from v then d < u, v > is not necessarily equal to
d < v, u >.

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 14


U n i t - 5 ≻≻ G r a p h T h e o r y
❖ REACHABLE SET OF A GIVEN NODE
✓ The set of nodes which are reachable from a given node v is said to be the reachable set of v.
The reachable set of v is written as Rሺvሻ. For any subset S ⊆ V, the reachable set of S is the set
of nodes which are reachable from any node of S. This set is denoted by R(S).
EXAMPLE:

𝑣1 𝑣2 𝑣5 𝑣6 𝑣9

𝑣10
𝑣4 𝑣3 𝑣7 𝑣8

✓ In the above graph all the reachable sets are given as below
Rሺv1 ሻ = Rሺv2 ሻ = Rሺv3 ሻ = Rሺv4 ሻ = Rሺv5 ሻ = ሼv1 , v2 , v3 , v4 , v5 , v6 ሽ
Rሺv6 ሻ = ሼv6 ሽ, Rሺv7 ሻ = ሼv6 , v7 ሽ, Rሺv8 ሻ = ሼv6 , v7 , v8 ሽ, Rሺv9 ሻ = ሼv9 ሽ
Rሺv10 ሻ = ሼv10 ሽ, Rሺv5 , v8 , v9 , v10 ሻ = V = Rሺv1 , v8 , v9 , v10 ሻ
❖ NODE BASE
✓ In a digraph G = ሺV, Eሻ, a subset X ⊆ V is called a node base if its reachable set is V and no
proper subset of X has this property.
✓ In the above graph the set ሼv1 , v8 , v9 , v10 ሽ is a node base and similarly the set ሼv5 , v8 , v9 , v10 ሽ
is a node base.
❖ CONNECTEDNESS
✓ An undirected graph is said to be connected if for any pair of nodes of the graph the two nodes
are reachable from one another.
❖ WEAKLY CONNECTED
✓ A digraph is said to be weakly connected(connected) if it is connected as an undirected graph
in which the direction of the edge is neglected. i.e., if the graph when treated as an undirected
graph is connected.
❖ STRONGLY CONNECTED
✓ If for any pair of nodes of the graph both the nodes of the pair are reachable from one another
then the graph is called strongly connected.
❖ UNILATERALLY CONNECTED
✓ A simple digraph is said to be unilaterally connected if for any pair of nodes of the graph at
least one of the node of the pair is reachable from the other node.

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 15


U n i t - 5 ≻≻ G r a p h T h e o r y
NOTE:
✓ Observe that a unilaterally connected digraph is weakly connected but a weakly connected
digraph is not necessarily unilaterally connected.
✓ A strongly connected digraph is both unilaterally and weakly connected.

A B C
)

✓ The digraph in figure(A) is strongly connected, (B) is weakly connected but not unilaterally
connected while (C) is unilaterally connected but not strongly connected.
❖ STRONG, WEAK AND UNILATERAL COMPONENTS OF A GRAPH
✓ For a simple digraph, a maximal strongly connected subgraph is called a strong component.
Similarly, a maximal unilaterally connected subgraph is called a unilateral component and
maximal weakly connected subgraph is called a weak component.
✓ For the digraph given in above figure 3 4
6
ሼ1,2,3ሽ, ሼ4ሽ, ሼ5ሽ, ሼ6ሽ are the strong components.
ሼ1,2,3,4,5ሽ, ሼ6ሽ are the unilateral components.
ሼ1,2,3,4,5,6ሽ is the weak component because
the graph is weakly connected. 2 1 5

❖ METHOD-3: PATH, REACHABILITY AND CONNECTEDNESS

H 1 Give three elementary paths from v1 to v3 for the


𝑣1 𝑣4
digraph given in following figure. Is there any cycle
in the graph? What is the shortest distance between
v1 and v3 .

𝑣2 𝑣3

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 16


U n i t - 5 ≻≻ G r a p h T h e o r y

C 2 Give all elementary cycles for the following 𝑣1 𝑣4 𝑣5


graph. Obtain an acyclic digraph by deleting
one edge of the given digraph.

𝑣2 𝑣3

C 3 Prove that in a simple digraph, the length of any elementary path is less than or equal
to n-1, where n is the number of nodes in the graph. Similarly, the length of any
elementary cycle does not exceed n.

T 4 Find the diameter of the digraphs given in the examples 1 and 2.

H 5 Find the reachable set of ሼv1 , v4 ሽ, ሼv4 , v5 ሽ and ሼv3 ሽ for the digraph given in example-
2.

C 6 Find the reachable set for all the nodes in the following
𝑣1 𝑣2
digraph.

𝑣4
𝑣3

C 7 Find a node base for each of the digraphs given in the examples 1 and 2.

C 8 Determine whether the digraphs in example 1 and 2 are strongly, weakly or


unilaterally connected.

H 9 Find the strong, weak and unilateral component for the digraph given in the example
2.

T 10 Find the strong, weak and unilateral 3 4 6


component of the digraph given in the
following figure.
2 1
5

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 17


U n i t - 5 ≻≻ G r a p h T h e o r y
❖ APPLICATIONS TO REPRESENT RESOURCE ALLOCATION STATUS OF AN OPERATING
SYSTEM AND DETECTION AND CORRECTION OF DEADLOCKS:
✓ We shall now show how a simple digraph can be used to represent the resource allocation
status of an operating system.
✓ In a multi programmed computer system it appears that several programs are executed at
one time. In reality, the programs are sharing the resources of the computer system such as
tape units, disk devices, the central processor, main memory and compilers. A special set of
programs called an operating system controls the allocation of these resources to the
programs. When a program requires the use of a certain resource and the operating system
must ensure that the request is satisfied.
✓ It may happen that requests for resources are in conflict. For example, program A may have
control of resource r1 and require resource r2 but program B has control of resource r2 and
requires resource r1 . In such a case the computer system is said to be in a state known as
deadlock and the conflicting requests must be resolved. A directed graph can be used to
model resource requests and assist in the detection and correction of deadlocks.
✓ It is assumed that all resource requests of a program must be satisfied before that program
must be satisfied before that program can complete execution. If any requested resources are
unavailable at the time of the request the program will assume control of the resources which
are available but must wait for the unavailable resources.
✓ Let Pt = ሼp1 , p2 , … , pm ሽ represent the set of programs in the computer system at time t. Let
At ⊆ Pt be the set of active programs or programs that have been allocated at least a portion
of their resource requests at time t. Let R t = ሼr1 , r2 , … , rn ሽ represent the set of resources in
the system at time t. An allocation graph Gt is a directed graph representing the resource
allocation status of the system at time t and consisting of a set of nodes V = R t and a set of
edges E. Each resource is represented by a node of the graph. There is a directed edge from
node ri to rj if and only if there is a program pk in At that has been allocated resource ri but
is waiting for rj . 𝑟1
✓ For example, let R t = ሼr1 , r2 , r3 , r4 ሽ and 𝑝2
𝑝1
At = ሼp1 , p2 , p3 , p4 ሽ and the resource allocation status
be
𝑟2 𝑝2 𝑟4
𝑝4
p1 has resource r4 and requires r1
p2 has resource r1 and requires r2 and r3 𝑝3 𝑝4
p3 has resource r2 and requires r3
𝑟3
p4 has resource r3 and requires r1 and r4 .

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 18


U n i t - 5 ≻≻ G r a p h T h e o r y
Then the allocation graph at time t is given in figure.
✓ It can be shown that the state of deadlock exists in a computer system at time t if and only if
the allocation graph Gt contains strongly connected components. In the case of our example
the graph Gt is strongly connected.
❖ MATRIX REPRESENTATION OF A GRAPH
✓ A diagrammatic representation of a graph has limited usefulness. Furthermore, such a
representation is only possible when the number of nodes and edges is reasonably small. An
alternating method of representing graphs using matrices has several advantages. It is easy
to store and manipulate matrices and the graphs represented by them in a computer. Well
known operations of matrix algebra can be used to calculate paths, cycles and other
characteristics of a graph.
✓ Given a simple digraph G = ሺV, Eሻ, it is necessary to assume some kind of ordering of the
nodes of the graph in the sense that a particular node is called a first node, another a second
node and so on. Our matrix representation of G depends upon the ordering of the nodes.
❖ ADJACENCY MATRIX
✓ Let G = ሺV, Eሻ be a simple digraph in which V = ሼv1 , v2 , … , vn ሽ and the nodes are assumed to
be ordered from v1 to vn . An n × n matrix A whose elements aij are given by
1 if < vi , vj >∈ Eሺ If there is an edge from vi to vj ሻ
aij = {
0 otherwise
is called the adjacency matrix of the graph G.
✓ Recall that the adjacency matrix is the same as the relation matrix or the incidence matrix of
the relation E in V. Any element of the adjacency matrix is either 0 or 1.
EXAMPLE: 𝑣2
𝑣
𝑣11
✓ The adjacency matrix of the above graph is A =
0 1 0 0
቎0 0 1 1቏.
1 1 0 1
1 0 0 0 𝑣4 𝑣3

NOTE:
✓ The sum of all 1’s in a row indicates the outdegree of the corresponding node.
✓ The sum of all 1’s in a column indicates the indegree of the corresponding node.
EXAMPLE:
✓ From the adjacency matrix(A) of the above digraph we can calculate outdegree, indegree and
total degree of each nodes which as follow.

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 19


U n i t - 5 ≻≻ G r a p h T h e o r y
Node Outdegree Indegree Total degree
v1 1 2 3
v2 2 2 4
v3 3 1 4
v4 1 2 3
✓ An adjacency matrix completely defines a simple digraph.
❖ BOOLEAN (BIT) MATRIX
✓ Any matrix whose elements are either 0 or 1 is called a Boolean matrix or bit matrix.
NOTE:
✓ For a given digraph G =< V, E >, an adjacency matrix depends upon the ordering of the
elements of V. For different ordering of the elements of V we get different adjacency matrices
of the same graph G.
✓ However, any one of the adjacency matrices of G can be obtained from another adjacency
matrix of the same graph by interchanging some of the rows and the corresponding column
of the matrix. But the digraphs of both the matrix are isomorphic.
✓ If a digraph is reflexive then the diagonal elements of the adjacency matrix are 1s.
✓ The adjacency matrix for a symmetric digraph is also symmetric. i.e., aij = aji for all i and j.
✓ If a digraph is antisymmetric, then aij = 1 implies aji = 0 and aij = 0 implies that aji = 1 for
all i and j.
✓ For a null graph which consists of only n nodes but no edges, the adjacency matrix is a null
matrix.
✓ If there are loops at each node but no other edges in the graph then the adjacency matrix is
the identity matrix.
෩,
✓ If G = ሺV, Eሻ is a simple digraph whose adjacency matrix is A then the adjacency matrix of G
the converse of G, is the transpose of A, that is AT .
❖ PATH (REACHABILITY) MATRIX OF A GRAPH
✓ Let G =< V, E > be a simple digraph in which ȁVȁ = n and the nodes of G are assumed to be
ordered. An n × n matrix P whose elements are given by
1 if there exists a path from vi to vj
pij = {
0 otherwise
is called the path matrix (reachability matrix) of the graph G.

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 20


U n i t - 5 ≻≻ G r a p h T h e o r y
EXAMPLE: 𝑣 𝑣2
𝑣11
1 1 1 1
✓ The path matrix of given graph is P = ቎1 1 1 1቏.
1 1 1 1
1 1 1 1
𝑣4 𝑣3
NOTE:
✓ The path matrix can be calculated from the matrix Bn by
choosing pij = 1 if the element bnij of Bn is nonzero and pij = 0 if the element bnij of Bn is

zero. Where, Bn = A + A2 + A3 + ⋯ + An . A is adjacency matrix of given graph and n is


number of nodes in given graph.
❖ DETERMINE NUMBER OF PATHS OF LENGTH N THROUGH ADJACENCY MATRIX:
RESULT:
✓ Let A be the adjacency matrix of a digraph G. The element in the ith row and jth column of An
(n is a nonnegative integer) is equal to the number of paths of length n from the ith node to
the jth node.
EXAMPLE:
𝑣 𝑣2
✓ Find the path matrix of given graph using adjacency matrix. Also 𝑣11

find number of paths of length 4 between v2 & v4 from the


adjacency matrix and mention it from the given graph.
𝑣4 𝑣3
0 1 0 0
✓ The adjacency matrix of the given graph is A = ቎0 0 1 1቏.
1 1 0 1
1 0 0 0
✓ Here no. of nodes in the given graph is ȁVȁ = 4.
Hence, Bn = B4 = A + A2 + A3 + A4
0 1 0 0 0 0 1 1 2 1 0 1 1 2 1 1 3 4 2 3
= ቎0 0 1 1቏ + ቎2 1 0 1቏ + ቎1 2 1 1቏ + ቎2 2 2 3቏ = ቎5 5 4 6቏.
1 1 0 1 1 1 1 1 2 2 1 2 3 3 2 3 7 7 4 7
1 0 0 0 0 1 0 0 0 0 1 1 2 1 0 1 3 2 1 2
✓ From B4 we conclude that all entries are nonzero implies all entries of path matrix P are
1(one).
1 1 1 1
✓ Hence, path matrix P for the given graph is P = ቎1 1 1 1቏.
1 1 1 1
1 1 1 1
✓ The number of paths of length 4 between v2 & v4 is the element of 2nd row and 4th column of
A4 , which is 3.
✓ The paths of length 4 from v2 to v4 are

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 21


U n i t - 5 ≻≻ G r a p h T h e o r y
P1 = ሺ< v2 , v3 >, < v3 , v1 >, < v1 , v2 >, < v2 , v4 >ሻ
P2 = ሺ< v2 , v4 >, < v4 , v1 >, < v1 , v2 >, < v2 , v4 >ሻ
P3 = ሺ< v2 , v3 >, < v3 , v2 >, < v2 , v3 >, < v3 , v4 >ሻ.
NOTE:
✓ The path matrix only shows the presence or absence of at least one path between a pair of
points and also the presence or absence of a cycle at any node. It does not show all the paths
that may exist. In this sense a path matrix does not complete information about a graph as
does the adjacency matrix. The path matrix is important in its own right.
✓ It may be remarked that if we are interested in knowing the reachability of one node from
another, it is sufficient to calculate Bn−1 = A + A2 + ⋯ + An−1 , because a path of length n
cannot be elementary for graph with n nodes.
✓ For the purpose of reachability, every node is assumed to be reachable from itself.
❖ WARSHALL’S ALGORITHM TO PRODUCE PATH MATRIX:
✓ Let G be a directed graph with m vertices v1 , v2 , … , vm . Suppose we want to find the path
matrix P of the graph G. Warshall gave an algorithm which is must more efficient than
calculating the powers of the adjacency matrix A.
✓ First we define m-square Boolean matrices P0 , P1 , … , Pm as follows. Let Pk [i, j] denote the ijth
entry of the matrix Pk . Then we define:
1 if there is a simple path from vi to vj which does not use
Pk [i, j] = ൞ any others vertices except possibly v1 , … , vk .

0 otherwise
✓ That is P0 [i, j] = 1 if there is an edge from vi to vj .
P1 [i, j] = 1 if there is a simple path from vi to vj which does not use any other vertex except
possibly v1 .
P2 [i, j] = 1 if there is a simple path from vi to vj which does not use any other vertices except
possibly v1 and v2 . And so on.
✓ Observe that the first matrix P0 = A is the adjacency matrix of G. Furthermore, since G has
only m vertices, the last matrix Pm = P is the path matrix of G.
✓ Warshall observed that Pk [i, j] = 1 can occur only if one of the following two cases occurs:
1. There is a simple path from vi to vj which does not use any other vertices except possibly
v1 , v2 , … , vk−1 ; hence Pk−1 [i, j] = 1.
2. There is a simple path from vi to vk and a simple path from vk to vj where each simple path
does not use any other vertices except possibly v1 , v2 , … , vk−1 . Hence Pk−1 [i, k] =
1 & Pk−1 [k, j] = 1.

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 22


U n i t - 5 ≻≻ G r a p h T h e o r y
These two cases are pictured as follows:
(1) vi → ⋯ → vj and (2) vi → ⋯ → vk → ⋯ → vj
✓ Here → ⋯ → denotes part of a simple path which does not use any other vertices except
possibly v1 , v2 , … , vk−1 . Accordingly the elements of Pk can be obtained by
Pk [i, j] = Pk−1 [i, j] ⋁ ሺPk−1 [i, k] ⋀ Pk−1 [k, j]ሻ.
✓ where we use the logical operations of ⋀ሺANDሻ and ⋁ሺORሻ. In other words we can obtain each
entry in the matrix Pk by looking at only three entries in the matrix Pk−1 .
❖ ALGORITHM:
✓ A directed graph G with M vertices is maintained in memory by its adjacency matrix A. This
algorithm finds the (Boolean) path matrix P of the graph G.
✓ Step 1.
Repeat for I, J = 1, 2, … , M: [initializes P. ]
If A[I, J] = 0, then: Set P[I, J]: = 0;
Else: Set P[I, J] ≔ 1.
[End the loop.]
✓ Step 2.
Repeat steps 3 and 4 for K = 1, 2, … , M: [Updates P.]
✓ Step 3.
Repeat Step 4 for I = 1, 2, … , M:
✓ Step 4.
Repeat for J = 1, 2, … , M:
Set P[I, J]: = P[I, J] ⋁ ሺP[I, K] ⋀ P[K, J]ሻ.
[End of loop.]
[End of step 3 loop.]
[End of step 2 loop.]
✓ Step 5.
Exit.
❖ METHOD-4: MATRIX REPRESENTATION OF A GRAPH

T 1 Obtain the adjacency matrix A of the digraph


𝑣1
given in the figure. Find the elementary paths of
lengths 1 and 2 from v1 to v4 . Show that there is
𝑣2 𝑣4
also a simple path of length 4 from v1 to v4 . Verify
the results by calculating A2 , A3 & A4 . 𝑣3

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 23


U n i t - 5 ≻≻ G r a p h T h e o r y

C 2 Find A and A2 without matrix multiplication for 𝑣 𝑣2


𝑣11
the given digraph. Where, A is an adjacent matrix.

𝑣4 𝑣3

T 3 From the adjacency matrix of given graph


calculate outdegree, indegree and total 2
1
degree of each nodes and also verify it from
the graph.

4 3

H 4 Find the adjacency matrix A and path matrix from B4 = 4


A + A2 + A3 + A4 for the given graph. Also verify path
matrix from given graph.
3
2

C 5 Apply Warshall’s algorithm to produce 𝑣1


a path matrix for given graph.

𝑣5
𝑣2

𝑣4 𝑣3

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 24


U n i t - 5 ≻≻ G r a p h T h e o r y
❖ INTRODUCTION OF TREE
✓ Trees are useful in describing any structure which involves hierarchy. Familiar examples of
such structures are family trees, the decimal classifications of books in a library, the hierarchy
of positions in an organization, an algebraic expression involving operations for which
certain rules precedence are prescribed, etc.
❖ ACYCLIC GRAPH
✓ A digraph which does not have any cycle is called acyclic graph.
❖ TREE
✓ A tree is a connected acyclic graph.
❖ DIRECTED TREE
✓ A directed tree is an acyclic graph which has one node called root with indegree 0, while all
other nodes have indegree 1.
NOTE:
✓ Every directed tree must have at least one node. An isolated node is also a directed tree.
❖ FOREST
✓ A set of disjoint trees is called a forest.
❖ ROOT
✓ A directed tree which has a node with indegree 0 is called roots of tree.
❖ LEAF (TERMINAL) NODE
✓ In a directed tree, any node which has outdegree 0 is called a terminal node or a leaf.
❖ BRANCH NODE
✓ The nodes which are not terminal nodes are known as branch nodes.
❖ LEVEL OF A NODE
✓ The level of any node is the length of its path from the root.
✓ The level of the root of a directed tree is 0, while the level of any node is equal to its distance
from the root.
✓ Observe that all the paths in a directed tree are elementary and the length of a path from any
node to another node if such a path exists is the distance between the nodes because a
directed tree is acyclic.

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 25


U n i t - 5 ≻≻ G r a p h T h e o r y
EXAMPLE:

𝑣4 𝑣5 𝑣8 Level 3
Leaf node 𝑣4 𝑣5 𝑣8 Level 3

𝑣10 𝑣2 𝑣10 𝑣9
𝑣2 𝑣9 𝑣3 𝑣7 Level 2
𝑣3 𝑣7 Level 2

𝑣1 𝑣1 𝑣6 Level 1
𝑣6 Level 1

Branch
node 𝑣0 Level 0
𝑣0 Root Level 0

Undirected tree
Directed tree

❖ DIFFERENT REPRESENTATIONS OF A TREE


✓ There are several other ways in which a directed tree can be represented graphically.
✓ These methods of representation for the directed tree of figure 1 are given in figures A, B and
C. The method(A) uses the familiar technique of Venn diagrams to show subtrees, the
method(B) uses the convention of nesting parentheses and the method(C) method is the one
used in the list of contents of books.

𝑣4 𝑣5 𝑣8
𝑣0
𝑣1
𝑣2 𝑣10 𝑣9
𝑣3 𝑣7 𝑣2
𝑣3
𝑣1 𝑣4
𝑣6 𝑣5
𝑣6
𝑣7
𝑣0
𝑣8
𝑣9
Figure 1
𝑣10

Method C

ሺ𝑣0 ሺ𝑣1 ሺ𝑣2 ሻ ሺ𝑣3 ሺ𝑣4 ሻሺ𝑣5 ሻሻሻሺሺ𝑣6 ሺ𝑣7 ሺ𝑣8 ሻሻሺ𝑣9 ሻሺ𝑣10 ሻሻሻ

Method B

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 26


U n i t - 5 ≻≻ G r a p h T h e o r y

𝑣7 𝑣8

𝑣9
𝑣5
𝑣2 𝑣𝑣103
𝑣4
𝑣3 𝑣6
𝑣1

𝑣0

Method A

❖ BINARY TREE
✓ In a directed tree the outdegree of every
node is less than or equal to 2 then the
tree is called binary tree.
EXAMPLE: Figure A shows binary tree.
❖ FULL (COMPLETE)BINARY TREE
✓ If the outdegree of every node is exactly A B
equal to 2 or 0 then the tree is called a full
or complete binary tree.
EXAMPLE: Figure B shows binary
tree.
❖ M-ARY TREE
✓ In a directed tree the
outdegree of every node is
less than or equal to m then
the tree is called m-ary tree.
EXAMPLE: Figure C shows 3-ary
tree.
C D

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 27


U n i t - 5 ≻≻ G r a p h T h e o r y
❖ FULL (COMPLETE) M-ARY TREE
✓ If the outdegree of every node is exactly equal to m or 0 then the tree is called a full or
complete m-ary tree.
EXAMPLE: Figure D shows full 3-ary tree.
❖ DESCENDENT OF NODE U
✓ The node which is reachable from u is called descendent of u.
❖ SON OF NODE U
✓ The node which is reachable from u through a single edge is called son of u.
❖ POSITIONAL M-ARY TREE
✓ If we consider m-ary trees in which the m sons of any node are assumed to have m distinct
positions. If such positions are taken into account then the tree is called a positional m-ary
tree.
EXAMPLE:

0 1 0 1

00 01 10 11
00 10 11

A 000 001 110 111

0 1

0 1 0 1
01 10 11

C D

✓ Figure A shows a binary tree, B shows a full binary tree and C shows all four possible
arrangements of sons of a node in a binary tree. The binary trees shown in figure A and D are
distinct positional trees although they are not distinct ordered trees. In a positional binary
tree, every node is uniquely represented by a string over the alphabet ሼ0, 1ሽ, the root being
represented by an empty string. Any son of a node u has a string which is prefixed by the
string of u. The string of any terminal node is not prefixed to the string of any other node. The

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 28


U n i t - 5 ≻≻ G r a p h T h e o r y
set of strings which correspond to terminal node from a prefix code. Thus, the prefix code of
the binary tree in B is ሼ000, 001, 01, 10, 110, 111ሽ. A similar representation of nodes of a
positional m-ary tree by means of string over an alphabet {0, 1, …, m-1} is possible.
❖ CONVERTING ANY M-ARY TREE TO A BINARY TREE
Delete all the branches originating in every node except the left most branch.
Draw edges from a node to the node on the right, if any, which is situated at the same level.
Choose its left and right sons as below.
(a). The left son is the node which is immediately below the given node.
(b). The right son is the node to the immediate right of the given node on some horizontal
line.
EXAMPLE:

2 3 4 5

9 10 11
Given tree
6 7 8

1
2
3 4 5
3
2
6
4

10 11 7 8 5
6 7 8 9

Stage 1

10

11

Binary tree representation

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 29


U n i t - 5 ≻≻ G r a p h T h e o r y
❖ METHOD-5: PROPERTIES OF TREE AND ITS REPRESENTATIONS

H 1 Define with example: acyclic graph, tree, directed tree, forest, root, leaf node, branch
node and level of a node.

T 2 Explain different representation of a tree with example.

H 3 Define with example: binary tree, complete binary tree, m-ary tree and complete m-
ary tree.

C 4 Write the steps of converting any m-ary tree to a


binary tree and convert the following tree into a
binary tree.

❖ REPRESENTATIONS OF A BINARY TREE


✓ The representation of a binary tree is simple compared to those for general tree.
❖ LINKED-LIST
✓ Computer representation of trees based on linked allocation seems to be more popular
because of the ease with which nodes can be inserted in and deleted from a tree and because
tree structures can grow to an arbitrary size, a size which is often unpredictable.
✓ Linked allocation techniques will be used to represent binary trees. A number of possible
traversals which can be performed on binary trees are described. The subsections end with
a symbol table algorithm based on a tree structure.
✓ A binary tree has one root node with no descendants or else a left, or a right, or a left and
right subtree descendent(s). Each subtree descendant is also a binary tree and we do make
the distinction between its left and right branches. A convenient way of representing binary
trees is to used linked allocation techniques involving nodes with structure where LLINK or
RLINK contain a pointer to the left subtree respectively of the node in question. Data contains
the information which is to be associated with this particular node. Each pointer can have a
value NULL. LLINK DATA RLINK
✓ An example of a binary tree as a graph and its corresponding linked representation in
memory are given in figure A and B respectively. Observe the very close similarity between

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 30


U n i t - 5 ≻≻ G r a p h T h e o r y
the figures as drawn. Such a similarity illustrates that the linked storage representation of a
tree is closer to the logical structuring of the data involved. This property can be useful in
designing algorithms which process tree structures.

B E
B E

F
C D C D F

H G
A

❖ TREE TRAVERSAL
✓ Tree traversal is a procedure by which each node is processed exactly once in some
systematic manner.
❖ PRE-ORDER TRAVERSAL
✓ Process the root node.
Traverse the left subtree in pre-order.
Traverse the right subtree in pre-order.
❖ IN-ORDER TRAVERSAL
✓ Traverse the left subtree in in-order.
Process the root node.
Traverse the right subtree in in-order.
❖ POST ORDER TRAVERSAL
✓ Traverse the left subtree in post-order.
Traverse the right subtree in post-order.
Process the root node.
EXAMPLE:
✓ The pre-order, in-order and post-order traversals of the tree given in following table which
process the nodes in the following order:

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 31


U n i t - 5 ≻≻ G r a p h T h e o r y
ABCDEFGH (pre-order)
CBDAEFGH (in-order)
CDBHGFEA (post-order)
✓ The following table shows the trace of algorithm preorder for the above graph
Stack contents P Visit P Output String
NA A A
NE NB B AB
NE ND NC C ABC
NE ND NULL
NE ND D ABCD
NE NULL
NE E ABCDE
NF NULL
NF F ABCDEF
NG G ABCDEFG
NH NULL
NH H ABCDEFGH
NULL

❖ ALGORITHM PREORDER:
✓ Given a binary tree whose root node address is given by a variable T and whose node
structure is the same as previously described, this algorithm traverses the tree in preorder.
An auxiliary stack S is used and TOP is the index of the top element of S. P is a temporary
variable which denotes when we are in the tree.
1. [Initialize] If T = NULL, then Exit (the tree has no root and therefore is not a proper binary
tree); otherwise set P ← T and TOP ← 0.
2. [Visit node, stack right branch address and go left] Process node P. If RLINKሺPሻ ≠ NULL,
then set TOP ← TOP + 1 and S[TOP] ← RLINKሺPሻ. Set P ← LLINKሺPሻ.
3. [End of chain?] If P ≠ NULL, then go to step 2.
4. [Unstack a right branch address] If TOP=0, then Exit; otherwise set P ← S[TOP], TOP ←
TOP − 1, and go to step 2.
✓ In the second and third steps of the algorithm, we visit and process a node. The address of
the right branch of such a node, if it exists, is stacked and a chain of left branches is followed
until this chain ends. At this point we enter step 4 and delete from the stack the address of

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 32


U n i t - 5 ≻≻ G r a p h T h e o r y
the root node of the most recently encountered right subtree and process it according to steps
2 and 3. A trace of the algorithm for the binary tree given in the above graph appears in above
table, where the rightmost element in the stack is considered to be its top element and the
notation “NE,” for example, denotes the address of node E. The visit of a node in this case
merely involves the output of the label for that node.
❖ ALGORITHM POSTORDER:
✓ The same node structure described previously is assumed and T is again a variable which
contains address of the root of the tree. A stack S with its top element pointer is also required,
but in this case each node will be stacked twice namely once when its left subtree is traversed
and once when its right subtree is traversed. On completion of these two traversals, the
particular node being considered is proceed. Hence, we must be able to distinguish two types
of stack entries. The first type of entry indicates that a left subtree is being traversed, while
the second indicates the traversal of a right subtree. For convenience we will use negative
pointer values for the second type of entry. This of course assumes that valid pointer data is
always nonzero and positive.
1. [Initialize] If T = NULL, then Exit (the tree has no root and therefore is not a proper binary
tree); otherwise set P ← T and TOP ← 0.
2. [Stack node address and go left] Set TOP ← TOP + 1, S[TOP] ← P and P ← LLINKሺPሻ.
3. [End of chain?] If P ≠ NULL, then go to step 2.
4. [Unstack a node address] If TOP=0, then Exit; otherwise set P ← S[TOP], TOP ← TOP − 1,
and go to step 2.
5. [Restack address if right subtree is not traversed] If P<0, then go to step 6; otherwise set
TOP ← TOP + 1, S[TOP] ← −P, P ← RLINKሺPሻ, and go to step 3.
6. [Visit node] Set P ← −P, process node P, and go to step 4.
✓ In the second and third steps, a chain of left branches is followed and the address of each
node which is encountered is stacked. At the end of such a chain, the stack entry for the last
node encountered is checked against zero. If it is positive, the negative address of that node
is restacked and the right branch of this node is taken and processed according to steps 2 and
3. If the stack value is negative however we have finished traversing the right subtree of that
node. The node is then processed and the next stack entry is subsequently checked.
❖ APPLICATIONS OF LIST STRUCTURES AND GRAPHS
✓ Representation of a structure which is more general than a tree such a structure is called a
list structure and several programming languages have been developed to allow easy
programming languages have been developed to allow easy processing of structures similar

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 33


U n i t - 5 ≻≻ G r a p h T h e o r y
to those that will be described. The need for list processing arose from the high cost of rapid
computer storage and the unpredictable nature of the storage requirements of computer
programs and data. There are many symbol manipulation applications in which this
unpredictability is particularly acute. It will be shown that a list structure can be used to
represent a directed graph. The representations of a general graph structures are based not
only nature of the data but also on the operations which are to be performed on the data.

❖ METHOD-6: TYPES OF TREE TRAVERSAL AND ITS ALGORITHMS

T 1 Explain representation of a binary tree by linked allocation technique with example.

H 2 Define: tree traversal, pre-order traversal, in-order traversal and post-order


traversal.

C 3 Write algorithm on pre-order traversal.

C 4 Write algorithm on post-order traversal.

H 5 Discuss application of list structures and graphs.

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY _ DM (3140708) 34

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy