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

Data Structures - Trees & Graphs

The document provides an overview of trees and binary trees, detailing their definitions, basic terminologies, and representations. It explains key concepts such as nodes, edges, and various types of binary trees, including full and complete binary trees. Additionally, it covers traversal methods for binary trees, specifically inorder, postorder, and preorder traversals.

Uploaded by

Karthik S
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Data Structures - Trees & Graphs

The document provides an overview of trees and binary trees, detailing their definitions, basic terminologies, and representations. It explains key concepts such as nodes, edges, and various types of binary trees, including full and complete binary trees. Additionally, it covers traversal methods for binary trees, specifically inorder, postorder, and preorder traversals.

Uploaded by

Karthik S
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 56

DATA STRUCTURES – Trees & Graphs

S.Karthik, Assistant Professor,


Department of Information Technology,
Sri Ramakrishna College of Arts & Science,
Coimbatore
1
TREES
Definitions and Basic Terminologies
Definition :A tree is defined as a finite set of one or more nodes such that
(i) there is a specially designated node called the root and
(ii) the rest of the nodes could be partitioned into t disjoint sets (t ≥ 0) each
set representing a tree Ti, i = 1, 2, . . . t known as subtree of the tree.
•A node in the definition of the tree represents an item of information, and
the links between the nodes termed as branches, represent an association
between the items of information. Figure 8.1 illustrates a tree

2
Sri Ramakrishna College of Arts and Science
Definitions - Continued
The definition of the tree emphasizes on the aspect of
(i) connectedness and
(ii) absence of closed loops or what are termed cycles.
Beginning from the root node, the structure of the tree
permits connectivity of the root to every other node in
the tree.
•In general, any node is reachable from any where in the
tree. Also, with branches providing the links between the
nodes, the structure ensures that no set of nodes link
together to form a closed loop or a cycle.

Sri Ramakrishna College of Arts and Science


3
TREES : BASIC TERMNOLOGIES
Terminologies used in Trees
Root – The top node in a tree.
Child – A node directly connected to another node when moving
away from the Root.
Parent – The converse notion of a child.
Siblings – Children of the same parent node.
Descendant – A node reachable by repeated proceeding from
parent to child.
Ancestor – A node reachable by repeated proceeding from child
to parent.
Leaf – A node with no children.
Internal node – A node with at least one child.
External node – A node with no children.
4
Sri Ramakrishna College of Arts and Science
TREES : BASIC TERMNOLOGIES
Degree of the node – Number of sub trees of a node.
Edge – Connection between one node to another.
Path – A sequence of nodes and edges connecting a node with a
descendant.
Level – The level of a node is defined by 1 + (the number of
connections between the node and the root).
Height of node – The height of a node is the number of edges on
the longest downward path between that node and a leaf.
Height or Depth of tree – The maximum level of any node in the
tree. The height of a tree is the height of its root node. The
length of the longest path from the root node to that node.
depth of the tree = height of the tree – 1
Forest – A forest is a set of zero or more (n ≥ 0) disjoint trees.

5
Sri Ramakrishna College of Arts and Science
BASIC TERMNOLOGIES - Contd

Root- The first node from where the tree originates is called as a root node.
In any tree, there must be only one root node.
We can never have multiple root nodes in a tree data structure.
Edge- The connecting link between any two nodes is called as an edge.
In a tree with n number of nodes, there are exactly (n-1) number of edges.

Sri Ramakrishna College of Arts and Science


6
BASIC TERMNOLOGIES - Contd

Degree- Degree of a node is the total number of children of that node.


Degree of a tree is the highest degree of a node among all the nodes in the tree.

Here,
Degree of node A = 2
Degree of node B = 3
Degree of node C = 2
Degree of node D = 0
Degree of node E = 2
Degree of node F = 0
Degree of node G = 1
Degree of node H = 0
Degree of node I = 0
Degree of node J = 0
Degree of node K = 0
Sri Ramakrishna College of Arts and Science
7
BASIC TERMNOLOGIES – Contd

Sri Ramakrishna College of Arts and Science


8
BASIC TERMNOLOGIES - Contd

Sri Ramakrishna College of Arts and Science


9
Representation of Trees
Though trees are better understood in their pictorial forms, a
common representation of a tree to suit its storage in the
memory of a computer, is a list. The tree of Fig. 8.1 could be
represented in its list form as (A (B(F,G,H), C, D(I), E(J,K(L))) ). The
root node comes first followed by the list of subtrees of the
node. This is repeated for each subtree in the tree. This list form
of a tree, paves way for a naïve representation of the tree as a
linked list. The node structure of the linked list is shown below

The DATA field of the node stores the information content of the
tree node. A fixed set of LINK fields accommodate the pointers to
the child nodes of the given node. In fact the maximum number
of links the node would require is equal to the degree of the tree.
10
Sri Ramakrishna College of Arts and Science
Representation of Trees - Contd

The linked representation of the tree shown in Fig. 8.1 is illustrated in Fig. 8.2 (b).
Observe the colossal wastage of space by way of null pointers!

Sri Ramakrishna College of Arts and Science


11
Representation of Trees
An alternative representation would be to use a node structure as
shown in Fig. 8.3(a).
Here TAG =1 indicates that the next field (DATA / DOWN LINK) is
occupied by data (DATA) and TAG = 0 indicates that the same is
used to hold a link (DOWN LINK).
The node structure of the linked list holds a DOWNLINK whenever
it encounters a child node which gives rise to a subtree.
Thus the root node A has four child nodes, three of which viz., B,
D and E give rise to subtrees. Note the DOWN LINK active fields of
the nodes in these cases with TAG set to 0.
In contrast, observe the linked list node corresponding to C which
has no subtree. The DATA field records C with TAG set to 1.

12
Sri Ramakrishna College of Arts and Science
Representation of Trees - Contd

Sri Ramakrishna College of Arts and Science


13
Representation of Trees
Example 8.1
We illustrate a tree structure in the organic evolution
which deals with the derivation of new species of plants
and animals from the first formed life by descent with
modification.
Figure 8.4 (a) illustrates the tree and
Fig. 8.4 (b) shows its linked representation.

14
Sri Ramakrishna College of Arts and Science
Representation of Trees - Contd

Sri Ramakrishna College of Arts and Science


15
Binary Trees: Basic Terminologies & Types
Basic terminologies
A binary tree has the characteristic of all nodes having at most two branches, that is, all
nodes have a degree of at most 2. A binary tree can therefore be empty or consist of a root
node and two disjointed binary trees termed left subtree and right subtree. Figure 8.5
illustrates a binary tree.

It is essential that the distinction between trees and binary trees are brought out clearly.
While a binary tree can be empty with zero nodes, a tree can never be empty.
Again while the ordering of the subtrees in a tree is immaterial, in a binary tree the distinction
of left and right subtrees are very clearly maintained.
All other terminologies applicable to trees such as levels, degree, height, leaf nodes, parent,
child, siblings etc. are also applicable to binary trees.

16
Sri Ramakrishna College of Arts and Science
Binary Trees: Basic Terminologies & Types
However, there are some important observations regarding binary trees.
(i) The maximum number of nodes on level i of a binary tree is 2i –1, i ≥ 1.
(ii) The maximum number of nodes in a binary tree of height h is 2h– 1, h ≥ 1.
(iii) For any non empty binary tree, if to is the number of terminal nodes and t2 is
the number of nodes of degree 2, then to = t2 + 1
From the figure 8.5 the maximum number of nodes on level 3 is 23-1 = 22 = 4. Also with the
height of the binary tree being 3, the maximum number of nodes = 23-1 = 7. [Again to = 4
and t2 = 3 which yields to = t2 + 1.]

Types of binary trees :


1.Full binary tree of height h : A binary tree of height h which has all its permissible
maximum number of nodes viz., 2h– 1 intact is known as a full binary tree of height h.
Figure 8.6(a) illustrates a full binary tree of height 4.
Note the specific method of numbering the nodes.
2. Complete binary tree : A binary tree with n’ nodes and height h is complete if its nodes
correspond to the nodes which are numbered 1 to n (n’≤ n) in a full binary tree of height h.
In other words, a complete binary tree is one in which its nodes follow a sequential
numbering that increments from a left-to-right and top-to-bottom fashion. A full binary tree
is therefore a special case of a complete binary tree.
17
Sri Ramakrishna College of Arts and Science
Types of Binary Trees - Contd
•Also, the height of a complete binary tree with n elements has a height h given by h = log2 (n +
1).
•A complete binary tree obeys the following properties with regard to its node numbering:
(i) If a parent node has a number i then its left child has the number 2i (2i<n). If 2i> n then i
has no left child.
(ii) If a parent node has a number i, then its right child has the number 2i + 1 (2i + 1 ≤ n). If
2i + 1 > n then i has no right child.
(iii) If a child node (left or right) has a number i then the parent node has the number
i/2 if i ≠ 1. If i = 1 then i is the root and hence has no parent.
In the full binary tree of height 4 illustrated in Fig. 8.6(a), observe how the parent-child
numbering is satisfied. For example, consider node s (number 4), its left child w has the
number 2*4=8 and its right child has the number 2*4+1=9. Again the parent of node v
(number 7) is the node with number [7/2] =3 (i.e.) node 3 which is r.

Figure 8.6(b) illustrates an example complete binary tree. A binary tree which is dominated
solely by left child nodes or right child nodes is called a skewed binary tree or more
specifically left skewed binary tree or right skewed binary tree respectively.
Figure 8.6(c) illustrates examples of skewed binary trees.

Sri Ramakrishna College of Arts and Science


18
Types of Binary Trees - Contd

19
Sri Ramakrishna College of Arts and Science
Representation of Binary Trees
A binary tree could be represented by using a
1. Sequential data structure (arrays) and 2. Linked data structure
Array representation of binary trees (Sequential data structure )
To represent the binary tree as an array, the sequential numbering system emphasized by a
complete binary tree comes in handy. Consider the binary tree shown in Fig. 8.7(a). The array
representation is as shown in Fig. 8.7(b). The association of numbers pertaining to parent and
left/right child nodes makes it convenient to access the appropriate cells of the array. However,
the missing nodes in the binary tree and hence the corresponding array locations, are left
empty in the array. This obviously leads to a lot of wastage of space. However, the array
representation ideally suits a full binary tree due to its non wastage of space.

20
Sri Ramakrishna College of Arts and Science
Linked Representation of Binary Trees
Linked representation of binary trees : The linked representation of a binary tree has the node
structure shown in Fig. 8.8(a). Here, the node, besides the DATA field, needs two pointers
LCHILD and RCHILD to point to the left and right child nodes respectively. The tree is accessed by
remembering the pointer to the root node of the tree.

In the binary tree T shown in Fig. 8.8(b), LCHILD (T) refers to the node storing b and
RCHILD(LCHILD (T )) refers to the node storing d and so on. The following are some of the important
observations regarding the linked representation of a binary tree:
(i) If a binary tree has n nodes then the number of pointers used in its linked representation is 2*n.
(ii) The number of null pointers used in the linked representation of a binary tree with n nodes is n+1.
However, in a linked representation it is difficult to determine a parent given a child node. In any
case if an application so requires, a fourth field PARENT may also be included in the structure. 21
Binary Tree Traversals

Binary Tree Traversals


An important operation that is performed on a binary tree is its traversal. A traversal of a
binary tree is where its nodes are visited in a particular but repetitive order, rendering a
linear order of the nodes or information represented by them.
A traversal is governed by three actions, viz. Move left (L), Move Right (R) and Process Node
(P). In all, it yields six different combinations of LPR, LRP, PLR, PRL, RPL and RLP. Of these, three
have emerged significant in computer science. They are,
i) LPR — - Inorder traversal
ii) LRP — - Postorder traversal
iii) PLR — - Preorder traversal.

The algorithms for each of the traversals are elaborated here.


22
Sri Ramakrishna College of Arts and Science
Inorder Traversal

Inorder Traversal The traversal keeps moving left in the binary tree until one can move no
further, processes the node and moves to the right to continue its traversal again. In the
absence of any node to the right, it retracts backwards by a node and continues the traversal.
Algorithm 8.1 illustrates a recursive procedure to perform inorder traversal of a binary tree.
For clarity of application, the action Process Node (P) is interpreted as Print node. Observe the
recursive procedure reflect the maxim LPR repetitively.

Execute the traversal of the binary tree as traverse left subtree, process root node and
traverse right subtree. Repeat the same for each of the left and right subtrees encountered.
The output of the call to the procedure INORDER_TRAVERSAL with the root of the appropriate
subtree as its input. The final output of the inorder traversal (from Fig.8.9) is S T Q P W U R V.
23
Sri Ramakrishna College of Arts and Science
Inorder Traversal

Example 8.2 An easy method to obtain the traversal would be to run one’s fingers on
the binary tree with the maxim: move left until no more nodes, process node, then
move right and continue the traversal.

24
Sri Ramakrishna College of Arts and Science
Inorder Traversal

25
Sri Ramakrishna College of Arts and Science
Inorder Traversal

26
Sri Ramakrishna College of Arts and Science
Inorder Traversal

27
Sri Ramakrishna College of Arts and Science
Post Order Traversal
Postorder Traversal
The traversal proceeds by keeping to the left until it is no further possible, turns right to
begin again or if there is no node to the right, processes the node and retraces its direction by
one node to continue its traversal. Algorithm 8.2 illustrates a recursive procedure to perform
post order traversal of a binary tree. The recursive procedure reflects the maxim LRP invoked
repetitively.
Example : The postorder traversal of the binary tree shown in Fig. 8.9.
Output : The output of Postorder traversal is TSQWUVRP.

Sri Ramakrishna College of Arts and Science


28
Post Order Traversal
Example 8.3 As pointed out in Example 8.2, an easy method would be to run one’s
fingers on the binary tree with the maxim: move left until there are no more nodes
and turn right to continue traversal.
If there is no right node, process node, retract by one node and continue traversal. An
alternative method would be to trace the recursive steps of the algorithm using the
scheme: Traverse left subtree, Traverse right subtree and Process root node.

Sri Ramakrishna College of Arts and Science


29
Post Order Traversal

Sri Ramakrishna College of Arts and Science


30
Post Order Traversal

Sri Ramakrishna College of Arts and Science


31
Post Order Traversal

Sri Ramakrishna College of Arts and Science


32
Preorder Traversal

Preorder Traversal
The traversal processes every node as it moves left until it can move no further. Now it turns
right to begin again or if there is no node in the right, retracts until it can move right to
continue its traversal. The recursive procedure for the preorder traversal is illustrated in
Algorithm 8.3. The recursive procedure reflects the maxim PLR invoked repetitively.
Example : The preorder traversal of the binary tree shown in Fig. 8.9.
Out put of the Preorder traversal : PQSTRUWV.

33
Sri Ramakrishna College of Arts and Science
Preorder Traversal

Example 8.4 An easy method as discussed before would be to trace the traversal on the binary
tree using the maxim: Process nodes while moving left until no more nodes, turn right, and
otherwise retract to continue the traversal.
An alternative method is to trace the recursive steps of the algorithm using the following
scheme: Execute the traversal of the binary tree as, process root node, traverse left subtree
and traverse right subtree, repeating the same for each of the left and right subtrees
encountered.

34
Sri Ramakrishna College of Arts and Science
Preorder Traversal

35
Sri Ramakrishna College of Arts and Science
Preorder Traversal

36
Sri Ramakrishna College of Arts and Science
Preorder Traversal

37
Sri Ramakrishna College of Arts and Science
Preorder Traversal

(i) Given a preorder traversal of a binary tree, the root node


is the first occurring item in the list.
(ii)Given a postorder traversal of a binary tree, the root node
is the last occurring item in the list.
(iii)Inorder traversal does not directly reveal the root node of
the binary tree.
(iv)An inorder traversal coupled with any one of preorder or
post order traversal helps trace back the structure of the
binary tree.

38
Sri Ramakrishna College of Arts and Science
Threaded Binary Tree
The linked representation of the binary tree showed that for a binary tree with n nodes, 2n
pointers are required of which (n+1) are null pointers.
A.J. Perlis and C.Thornton devised a prudent method to utilize these (n+1) empty pointers,
introducing what are called threads. Threads are also links or pointers but replace null
pointers by pointing to some useful information in the binary tree. Thus, for a node NODE if
RCHILD(NODE) is NIL then the null pointer is replaced by a thread which points to the node
which would occur after NODE when the binary tree is traversed in inorder. Again if LCHILD
(NODE) is NIL then the null pointer is replaced by a thread to the node which would
immediately precede NODE when the binary tree is traversed in inorder.
Figure 8.10. illustrates a threaded binary tree. The threads are indicated using broken lines to
distinguish them from the normal links indicated with solid lines. The inorder traversal of the
binary tree is also shown in the figure.

Note that the left child of G and the right child of E have threads which are left dangling due
to the absence of an inorder predecessor and successor respectively.
39
Sri Ramakrishna College of Arts and Science
Representation of Threaded Binary Tree

There are two representations of threads.


i) One-way threading : Here a thread appears only on the
RCHILD field of a node, when it is null, pointing to the inorder
successor of the node
ii) Two-way threading : Here a thread appears in the LCHILD field
also, if it is null, which points to the inorder predecessor of the
node. However, the first and the last of the nodes in the inorder
traversal will carry dangling threads.
Linked representation of a threaded binary tree
A linked representation of the threaded binary tree (two-way threading) has a

40
Sri Ramakrishna College of Arts and Science
Threaded Binary Tree

•In order to avoid confusion while processing the threaded binary tree when the LCHILD and
RCHILD fields are utilized to represent both links and threads . In the node structure includes
two more fields which act as flags to indicate if the LCHILD and RCHILD fields represent a
thread or a link.

•If the LEFT THREAD TAG or RIGHT THREAD TAG is marked true then LCHILD and RCHILD fields
represent threads otherwise they represent links Also, to tuck in the dangling threads which
are bound to arise, the linked representation of a threaded binary tree includes a head node.
The dangling threads point to the head node.

•The head node by convention has its LCHILD pointing to the root node of the threaded binary
tree and therefore has its LEFT THREAD TAG set to false. The RIGHT THREAD TAG field is also
set to false but the RCHILD link points to the head node itself. Figure 8.12(a) shows the linked
representation of an empty threaded binary tree and Fig. 8.12(b) that of a non-empty
threaded binary tree.

41
Sri Ramakrishna College of Arts and Science
Linked Representations of Threaded Binary Tree

42
Sri Ramakrishna College of Arts and Science
Graphs : Definitions & Basic Terminologies
Graph : A graph G = (V, E ) consists of a finite non empty set of vertices V also called points or
nodes and a finite set E of unordered pairs of distinct vertices called edges or arcs or links.
Example :Figure 9.3 illustrates a graph. Here V = {a, b, c, d} and E= {(a, b), (a, c), (b, c), (c,
d)}. However it is convenient to represent edges using labels as shown in the figure.
V : Vertices : {a, b, c, d}
E : Edges : {e1, e2, e3, e4}
A graph G = (V, E) where E = Ø, is called as a null or empty graph. A graph with one vertex and
no edges is called a trivial graph.

Multigraph : A multigraph G = (V, E) also consists of a set of vertices and edges except that E
may contain multiple edges (i.e.) edges connecting the same pair of vertices, or may contain
loops or self edges (i.e.) an edge whose end points are the same vertex.
Example : Figure 9.4 illustrates a multigraph Observe the multiple edges e 1, e2 connecting
vertices a, b and e5, e6 , e7 connecting vertices c, d respectively. Also note the self edge e 4 .
Note : Graphs do not contain multiple edges or loops but multigraphs contain multiple edges
or loops

43
Graphs : Definitions & Basic Terminologies
Directed Graphs or digraphs : Each edge can be traversed only in a specified direction
(ordered pairs of vertices). The edge eij is referred to as < vi, vj > which is distinct from < vj ,vi >
where vi, vj are distinct vertices. In < vi, vj >, vi is known as tail of the edge and vj as the head.
Undirected Graphs: Each edge can be traversed in either direction (Unordered pairs of
vertices). The edge eij of such an undirected graph is represented as (v i, vj) where vi, vj are
distinct vertices. Thus an undirected edge (vi, vj ) is equivalent to (vj ,vi). Figure 9.5(a-b)
illustrates a digraph and an undirected graph.

In Fig. 9.5(a), e1 is a directed edge between v1 and v2 , (i.e.) e1 = < v1, v2 >, whereas in Fig.9 .5(b)
e1 is an undirected edge between v1 and v2, (i.e.) e1 = (v1, v2). The list of vertices and edges of
graphs G1 and G2 are:
Vertices (G1) : {v1, v2, v3, v4 }
Vertices (G2) : {v1, v2, v3, v4}
Edges (G1) : {< v1, v2 > < v2, v1 > < v1, v3 > < v3, v4 > < v4, v3 >} or {e1, e2, e3, e4 , e5}
44
Graphs : Definitions & Basic Terminologies
In the case of an undirected edge (vi, vj) in a graph, the vertices vi, vj are said to be adjacent
or the edge (vi, vj) is said to be incident on vertices vi, vj. Thus in Fig. 9.5(b) vertices v1, v3 are
adjacent to vertex v2 and edges e1 : (v1, v2 ), e3 : (v2, v3) are incident on vertex v2.

On the other hand, if < vi, vj> is a directed edge, then vi is said to be adjacent to vi and vj is
said to be adjacent from vi. The edge < vi, vj> is incident to both vi and vj . Thus in Fig. 9.5(a)
vertices v2 and v3 are adjacent from v1, and v1 is adjacent to vertices v2 and v3. The edges
incident to vertex v3 are < v1, v3 >, < v3, v4 > and < v4, v3 >.

45
Sri Ramakrishna College of Arts and Science
Graphs : Definitions & Basic Terminologies
Complete graphs :
The number of distinct unordered pairs (vi, vj), vi ≠ vj in a graph with n vertices is nC2 =
An n vertex undirected graph with exactly n(n-1)/2 edges is said to be complete.

Figure 9.6 illustrates a complete graph. The undirected graph with 4 vertices has all its 4C2 =
6 edges intact.
In the case of a digraph with n vertices, the maximum number of edges is given by nP2 = n. (n
-1). Such a graph with exactly n.(n-1) edges is said to be a complete digraph.
Figure 9.7(a) illustrates a digraph which is complete and Fig. 9.7(b) a graph which is not
complete.

46
Sri Ramakrishna College of Arts and Science
Graphs : Definitions & Basic Terminologies
Subgraph : A subgraph G’ = (V’’, E’’) of a graph G = (V, E) is such that V’’ ⊆ V and E’’ ⊆ E.
Example : Figure 9.8 illustrates some subgraphs of the directed and undirected graphs
shown in Fig. 9.5 (Graphs G1 and G2)

Path : A path from a vertex vi to vertex vj in an undirected graph G is a sequence of vertices


Vi, V11 , V12, V13, …., V1 k, V j such that (Vi, V11 ), (V11 , V12), … , (V1 k, V j ) are edges in G. If G is
directed then the path from vi to vj more specially known as a directed path consists of
edges <Vi, V11 >, <V11 , V12 >, … , < V1 k, V j > in G.

47
Graphs : Definitions & Basic Terminologies
Figure 9.9(a) illustrates a path P1 from vertex v1 to v4 in graph G1 of Fig. 9.5(a) and Fig.
9.9(b) illustrates a path P2 from vertex v1 to v4 of graph G2 of Fig. 9.5(b).

The length of a path is the number of edges on it. In Fig. 9.9 the length of path P1 is 4 and the
length of path P2 is 3. A simple path is a path in which all the vertices except possibly the first
and last vertices are distinct.

48
Graphs : Definitions & Basic Terminologies
•In graph G2 (Fig. 9.5(b)), the path from v1 to v4 given by {(V1 , V2), (V2 , V3), (V3 , V4)} and

written as {V1 , V2 , V3, V4} is a simple path where as the path from V3 to V4 given by {(V3, V1),

(V1 , V2), (V2 , V3), (V3 , V4)} and written as {V3, V1 , V2 , V3, V4} is not a simple path but a path
due to the repetition of vertices.

•Also in graph G1 (Fig. 9.5(a)) the path from v1 to v3 given by {<V1, V2 >, <V2 , V1 >, <V1, V3 > }

written as {V1 , V2 , V1, V3} is not a simple path but a mere path due to the repetition of

vertices. However, the path from v2 to v4 given by { <V2 , V1 >, <V1, V3 > , <V3, V4 > } written

as {V2 , V1 , V3, V4} is a simple path.

•A cycle is a simple path in which the first and last vertices are the same. A cycle is also
known as a circuit, elementary cycle, circular path or polygon.
•In graph G2 (Fig. 9.5(b)) the path {v1, v2, v3, v1} is a cycle. Also, in graph G1 (Fig. 9.5(a)) the
path {v1, v2, v1} is a cycle or more specifically a directed cycle.

49
Graphs : Definitions & Basic Terminologies
•Connected graphs : Two vertices vi , vj in a graph G are said to be connected only if there is a

path in G between vi and vj . In an undirected graph if vi and vj are connected then it

automatically holds that vj and vi are also connected.

•An undirected graph is said to be a connected graph if every pair of distinct vertices vi , vj
are Connected. Example figure 9.10.
•Graph G2 (Fig. 9.5(b)) is connected where as graph G3 shown in Fig. 9.10 is not connected.

•In the case of an undirected graph which is not connected, the maximal connected
subgraph is called as a connected component or simply a component.
•Example Graph G3 (Fig. 9.10) has two connected components viz., graph G31 and G32.

50
Graphs : Definitions & Basic Terminologies
A directed graph is said to be strongly connected if every pair of distinct vertices vi , vj are
connected (by means of a directed path). Thus if there exists a directed path from vi to vj
then there also exists a directed path from vj to vi .
Graph G4 shown in Fig. 9.11 is strongly connected.

However, the digraph shown in Fig. 9.12 is not strongly connected but is said to possess two
strongly connected components. A strongly connected component is a maximal subgraph
that is strongly connected.

51
Graphs : Definitions & Basic Terminologies
Trees : A tree is defined to be a connected acyclic graph. The following properties are
satisfied by a tree:
(i) There exists a path between any two vertices of the tree, and
(ii) No cycles must be present in the tree. In other words, trees are acyclic.
Example Figure 9.13(a) illustrates a tree. Figure 9.13(b) illustrates graphs which are not
trees due to the violation of the property of acyclicity and connectedness respectively.

Figure 9.5.b
•Degree : The degree of a vertex in an undirected graph is the number of edges incident to
that vertex. A vertex with degree one is called as a pendant vertex or end vertex. A vertex
with degree zero and hence has no incident edges is called an isolated vertex.
•Example In graph G2 (Fig. 9.5(b)) the degree of vertex v3 is 3 and that of vertex v2 is 2.
In the case of digraphs, we define the indegree of a vertex v to be the number of edges
with v as the head and the outdegree of a vertex to be number of edges with v as the tail.
In graph G1 (Fig. 9.5(a)) the indegree of vertex v3 is 2 and the out degree of vertex v4 is 1.
Sri Ramakrishna College of Arts and Science
Graphs : Definitions & Basic Terminologies
Isomorphic graphs : Two graphs are said to be isomorphic if,
(i) they have the same number of vertices
(ii) they have the same number of edges
(iii) they have an equal number of vertices with a given degree.

The property of isomorphism can be verified on the lists of vertices and edges of the two
graphs G8 and G9 when superimposed as shown below:

53
Graphs : Definitions & Basic Terminologies
Cut set : A cut set in a connected graph G is the set of edges whose removal from G leaves G
disconnected, provided the removal of no proper subset of these edges disconnects the
graph G. Cut sets are also known as proper cut set or cocycle or minimal cut set.
Figure 9.15 illustrates the cut set of the graph G10.
The cut set {e1, e4} disconnects the graph into two components as shown in the figure.
{e5} is also another cut set of the graph.

54
Graphs : Definitions & Basic Terminologies
Labeled graphs : A graph G is called a labeled graph if its edges and / or vertices are assigned
some data. In particular if the edge e is assigned a non negative number l(e) then it is called
the weight or length of the edge e.
Example Figure 9.16 illustrates a labeled graph. A graph with weighted edges is also known
as a network.

Eulerian graph : A walk starting at any vertex going through each edge exactly once and
terminating at the start vertex is called an Eulerian walk or Euler line.
•The Koenigsberg bridge problem was in fact a problem of obtaining an Eulerian walk for
the graph concerned.
•Given a connected graph G, G is an Euler graph if all the vertices are of even degree.
Example Figure 9.17 illustrates an Euler graph {e1, e2, e3, e4} shows a Eulerian walk. The
even degree of the vertices may be noted.

55
Graphs : Definitions & Basic Terminologies
Hamiltonian circuit : A Hamiltonian circuit in a connected graph is defined as a closed walk
that traverses every vertex of G exactly once, except of course the starting vertex at which
the walk terminates.
A circuit in a connected graph G is said to be Hamiltonian if it includes every vertex of G. If
any edge is removed from a Hamiltonian circuit then what remains is referred to as a
Hamiltonian path. Hamiltonian path traverses every vertex of G.

Sri Ramakrishna College of Arts and Science 56

You might also like