Unit5 DIS

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 106

Noida Institute of Engineering and Technology, Greater

Noida

Tree and Graph

Unit: 5

Discrete Structure
ANAMIKA TIWARI
B. Tech 3rd Sem Assistant Professor
B.Tech AIML
Noida Institute of Engineering and Technology, Greater Noida

Introduction

ANAMIKA TIWARI

B.Tech and M.Tech in CSE with 4 Years Teaching Experience

 Area of Expertise: Image Processing and Software Engineering

 Attended and Conducted Numerous Workshops.


 Published about 5 National and International Papers in reputed Journals.
 Attend various FDPs and Webinar.

ANAMIKA TIWARI Discrete Structures


07/02/24 2
Unit 5
NOIDA INSTITUTE OF ENGINEERING & TECHNOLOGY, GREATER NOIDA(An

Autonomous Institute) EVALUATION SCHEME SEMESTER-III


End
Sl. Subject Codes Periods Evaluation Schemes
Subject Name Semester Total Credit
No.
L T P CT TA TOTAL PS TE PE

WEEKS COMPULSORY INDUCTION PROGRAM


1 AAS0303 Statistics and Probability 3 1 0 30 20 50 100 150 4
2 ACSE0306 Discrete Structures 3 0 0 30 20 50 100 150 3
Computer Organization &
3 ACSE0305
Architecture
3 0 0 30 20 50 100 150 3
Object Oriented Techniques
4 ACSE0302
using Java
3 0 0 30 20 50 100 150 3
5 ACSE0301 Data Structures 3 1 0 30 20 50 100 150 4
Foundations of Data
6 ACSDS0301
Science
3 0 0 30 20 50 100 150 3
Object Oriented Techniques
7 ACSE0352
using Java Lab
0 0 2 25 25 50 1
8 ACSE0351 Data Structures Lab 0 0 2 25 25 50 1
9 ACSDS0351 Data Analysis Lab 0 0 2 25 25 50 1
10 ACSE0359 Internship Assessment-I 0 0 2 50 50 1
Cyber Security* /
ANC0301 /
11 Environmental 2 0 0 30 20 50 50 1000
ANC0302
Science*(Non Credit)
MOOCs (For B.Tech.
12 Hons. Degree)
Subject Syllabus

ANAMIKA TIWARI Discrete


07/02/24 4
Structures Unit 5
Subject Syllabus

ANAMIKA TIWARI Discrete


07/02/24 5
Structures Unit 5
Subject Syllabus

ANAMIKA TIWARI Discrete


07/02/24 6
Structures Unit 5
Subject Syllabus

ANAMIKA TIWARI Discrete


07/02/24 7
Structures Unit 5
Application in CSE

1. Discrete Structures are useful in studying and describing objects and problems in branches
of computer science such as computer algorithms, programming languages.
2. Computer implementations are significant in applying ideas from discrete mathematics to real-
world problems, such as in operations research.
3. It is a very good tool for improving reasoning and problem-solving capabilities.
4. Discrete mathematics is used to include theoretical computer science, which is relevant to
computing.
5. Discrete structures in computer science with the help of process algebras.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 8


Course Objective

• The subject enhances one’s ability to develop logical thinking and ability to
problem solving.

• The objective of discrete structure is to enables students to formulate


problems precisely, solve the problems, apply formal proofs techniques
and explain their reasoning clearly.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 9


Course Outcome
Course At the end of course , the student will be able to Bloom’s
Outcome Knowledge
(CO) Level (KL)

CO1 Apply the basic principles of sets, relations & functions and K3
mathematical induction in computer science & engineering related
problems
CO2 Understand the algebraic structures and its properties to solve K2
complex problems

CO3 Describe lattices and its types and apply Boolean algebra to simplify K2,K3
digital circuit.
CO4 Infer the validity of statements and construct proofs using predicate K3,K5
logic formulas.
CO5 Design and use the non-linear data structure
ANAMIKA TIWARI like tree and graphs to K3,K6
Discrete
07/02/24 10
Structures
solve real world problems. Unit 5
Content
• Course Objective
• Course Outcome
• CO-PO Mapping
• Syllabus
• Prerequisite and Recap
• Graph and digraph
• Incidence and adjacency matrix
• Isomorphism
• Eulerian path and circuits in graphs
• Hamiltonian path and circuits
• Trees
• Four color theorem

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 11


Content

• Planar graphs
• Clique number
• Chromatic number
• Video links
• Daily Quiz
• Weekly Assignment
• MCQ
• Old Question papers
• Expected Question for University Exam
• Summary
• References.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 12


Course Objective
• The subject enhances one’s ability to develop logical thinking and ability to
problem solving.
• Demonstrate the ability to write and evaluate a proof or outline the basic
structure of and give examples of each proof technique described.
• Apply logical reasoning to solve a variety of problems.
• Use Mathematically correct terminology and notation.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 13


Course Outcome
Course At the end of course , the student will be able to Bloom’s
Outcome Knowledge
(CO) Level (KL)

CO1 Apply the basic principles of sets, relations & functions and K3
mathematical induction in computer science & engineering
related problems
CO2 Understand the algebraic structures and its properties to solve K2
complex problems
CO3 Describe lattices and its types and apply Boolean algebra to K2,K3
simplify digital circuit.
CO4 Infer the validity of statements and construct proofs using K3,K5
predicate logic formulas.
CO5 Design and use the non-linear data structure like tree and K3,K6
07/02/24 graphs to solve real world
ANAMIKA problems.
TIWARI Discrete Structures Unit 5 14
Program
Program Outcome
Outcomes

Engineering Graduates will be able to Understand:


1. Engineering knowledge
2. Problem analysis
3. Design/development of solutions
4. Conduct investigations of complex
5. Modern tool usage
6. The engineer and society
7. Environment and sustainability
8. Ethics
9. Individual and team work
10. Communication
11. Project management and finance
12. Life-long learning

ANAMIKA TIWARI Discrete Structures


07/02/24 15
Unit 5
CO-PO Mapping
CO-PO correlation matrix Discrete Structures (ACSE0306)

PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12

ACSE0306.1
2 2 3 3 2 2 - - 2 1 - 3

ACSE0306.2
1 3 2 3 2 2 - 1 1 1 2 2

ACSE0306.3
2 2 3 2 2 2 - 2 2 1 2 3

ACSE0306.4
2 2 2 3 2 2 - 2 2 1 1 3

ACSE306.5
3 2 2 2 2 2 - 2 1 1 1 2
Average 2 2.2 2.4 2.6 2 2 - 1.4 1.6 1 1.2 2.6

ANAMIKA TIWARI Discrete Structures Unit 5


07/02/24 16
End Semester Question Paper Templates (Offline Pattern/Online
Pattern

ANAMIKA TIWARI Discrete


07/02/24 17
Structures Unit 5
End Semester Question Paper Templates (Offline Pattern/Online
Pattern

ANAMIKA TIWARI Discrete


07/02/24 18
Structures Unit 5
End Semester Question Paper Templates (Offline Pattern/Online
Pattern

ANAMIKA TIWARI Discrete


07/02/24 19
Structures Unit 5
End Semester Question Paper Templates (Offline Pattern/Online
Pattern

ANAMIKA TIWARI Discrete


07/02/24 20
Structures Unit 5
End Semester Question Paper Templates (Offline Pattern/Online
Pattern

ANAMIKA TIWARI Discrete Structures


07/02/24 21
Unit 5
End Semester Question Paper Templates (Offline Pattern/Online
Pattern

ANAMIKA TIWARI Discrete


07/02/24 22
Structures Unit 5
End Semester Question Paper Templates (Offline Pattern/Online
Pattern

ANAMIKA TIWARI Discrete


07/02/24 23
Structures Unit 5
Prerequisite & Recap
Prerequisite
• Knowledge of Mathematics upto 12th standard.
Recap
• The fundamental concepts of Sets, Relations and Functions, Logic,
Probability and Boolean Algebra.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 24


Brief Introduction about the subject with video

Discrete mathematics is the study of mathematical structures that are


fundamentally discrete rather than continuous. In contrast to real numbers that
have the property of varying "smoothly", the objects studied in discrete
mathematics – such as integers, Trees, graphs, and statements in logic.

• https://www.youtube.com/watch?v=Dsi7x-A89Mw&list=PL0862D1A94725
2D20&index=28
• https://www.youtube.com/watch?
v=74l6t4_4pDg&list=PL0862D1A947252D20&index=29
• https://www.youtube.com/watch?
v=4d2XEn1j_q4&list=PL0862D1A947252D20&index=30

ANAMIKA TIWARI Discrete Structures


07/02/24 25
Unit 5
Unit Content

• Tree
• Binary Tree
• Tree Traversal
• Binary Search Tree
• Graphs
• Types of Graph
• Graph coloring

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 26


Unit Objective: Tree and Graph (CO5)

• Define how Tree and graphs will be serve as models for many
standard problems.
• How Graph theory will be used in Computer networks to minimize
the cost and time of delivery of data.
• To distinguish between two chemical compounds with the same
molecular formula but different structures.
• To solve shortest path problems between cities.
• To schedule exams and assign channels to television stations.

07/02/24 27
ANAMIKA TIWARI Discrete Structures Unit 5
Trees (CO5)

• A tree is a connected graph containing no cycles.


• A graph T is a tree if and only if between every pair of distinct
vertices of T there is a unique path.
• Let T be a tree with v vertices and e edges. Then e=v−1.
• Example:
G=(V,E) with V={a,b,c,d,e} and E={{a,b},{b,c},{c,d},{d,e}} is a
tree.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 28


Trees terminology (CO5)

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 29


Binary Trees (CO5)

A tree whose elements have at most 2 children is called a binary tree. Since each
element in a binary tree can have only 2 children, we typically name them the left
and right child.

A Binary Tree node contains following parts.


1.Data
2.Pointer to left child
3.Pointer to right child

ANAMIKA TIWARI Discrete Structures


07/02/24 30
Unit 5
Binary Trees (CO5)
Binary Tree(Properties)
1) The maximum number of nodes at level ‘l’ of a binary tree is 2 l.
Here level is the number of nodes on the path from the root to the node (including root and node).
Level of the root is 0.
This can be proved by induction.
For root, number of nodes = 20 = 1
Assume that the maximum number of nodes on level ‘l’ is 2 l
1. Since in Binary tree every node has at most 2 children, next level would have twice nodes, i.e. 2
* 2l
2. The Maximum number of nodes in a binary tree of height ‘h’ is 2 h+1 – 1.

ANAMIKA TIWARI Discrete


07/02/24 31
Structures Unit 5
Binary Tree (CO5)
Types of Binary Tree
1.Complete Binary Tree
2.Full Binary Tree
3.Balanced Binary Tree
4.A degenerate (or pathological) tree

ANAMIKA TIWARI Discrete


07/02/24 32
Structures Unit 5
Trees (CO5)
Complete Binary Tree: A Binary Tree is a complete Binary Tree if all the levels are
completely filled except possibly the last level and the last level has all keys as
left as possible
The following are examples of Complete Binary Trees

ANAMIKA TIWARI Discrete


07/02/24 33
Structures Unit 5
Binary Trees Traversal (CO5)
There are three ways which we use to traverse a tree

•In-order Traversal
•Pre-order Traversal
•Post-order Traversal

ANAMIKA TIWARI Discrete


07/02/24 34
Structures Unit 5
Inorder traversal (CO5)
Inorder traversal : Left Root Right.

B, D, A, G, E, C, H, F, I.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 35


Preorder traversal (CO5)
Preorder traversal : Root Left Right.

A, B, D, C, E, G, F, H, I

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 36


Postorder traversal (CO5)
Postorder traversal : Left Right Root

D, B, G, E, H, I, F, C, A.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 37


Binary Search Tree (CO5)

Binary Search tree exhibits a special behavior.

A node's left child must have a value less than its parent's value and the node's
right child must have a value greater than its parent value.

ANAMIKA TIWARI Discrete Structures


07/02/24 38
Unit 5
Binary Search Trees (C05)
BST Basic Operations

The basic operations that can be performed on a binary search tree data structure, are the
following −

•Insert − Inserts an element in a tree/create a tree.


•Search − Searches an element in a tree.
•Preorder Traversal − Traverses a tree in a pre-order manner.
•Inorder Traversal − Traverses a tree in an in-order manner.

•Postorder Traversal − Traverses a tree in a post-order manner.


We shall learn creating (inserting into) a tree structure and searching a data item in a
tree in this chapter. We shall learn about tree traversing methods in the coming chapter.

ANAMIKA TIWARI Discrete


07/02/24 39
Structures Unit 5
Definition of a Graph( CO 5)
• A generalization of the simple concept of a set of dots, links, edges or arcs.

• Representation:
Graph G =(V, E) consists set of vertices denoted by V, or by V(G) and set of
edges E, or E(G)

• In the above Graph, the set of vertices V = {0,1,2,3,4} and the set of edges E =
{01, 12, 23, 34, 04, 14, 13}.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 40


Definitions – Edge Type( CO 5)

Directed: Ordered pair of vertices. Represented as (u, v) directed from vertex u to v.

u v

Undirected: Unordered pair of vertices. Represented as {u, v}. Disregards


any sense of direction and treats both end vertices interchangeably
u v

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 41


Definitions – Edge Type( CO 5)

Loop: A loop is an edge whose endpoints are equal i.e., an edge joining
a vertex to it self is called a loop. Represented as {u, u} = {u}
u

Multiple Edges: Two or more edges joining the same pair of vertices

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 42


Directed graphs(Digraph) (CO 5)

G is a directed graph or digraph if each edge has been associated with an


ordered pair of vertices, i.e. each edge has a direction

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 43


Terminology – Undirected graphs(CO5)

 u and v are adjacent if {u, v} is an edge, e is called incident with u and v.


u and v are called endpoints of {u, v}
 Degree of Vertex (deg (v)): the number of edges incident on a vertex. A
loop contributes twice to the degree (why?).

 Pendant Vertex: deg (v) =1

 Isolated Vertex: deg (v) = 0

Representation Example: For V = {u, v, w} , E = { {u, w}, {u, w}, (u,v) }, deg
(u) = 2, deg (v) = 1, deg (w) = 1, deg (k) = 0, w and v are pendant , k is
isolated

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 44


Terminology – directed graphs(CO5)
 For the edge (u, v), u is adjacent to v OR v is adjacent from u, u – Initial
vertex, v – Terminal vertex

 In-degree (deg- (u)): number of edges for which u is terminal vertex

 Out-degree (deg+ (u)): number of edges for which u is initial vertex

Note: A loop contributes 1 to both in-degree and out-degree (why?)

Representation Example: For V = {u, v, w} , E = { (u, w), ( v, w), (u, v) }, deg -


(u) = 0, deg+ (u) = 2, deg- (v) = 1,
deg+ (v) = 1, and deg- (w) = 2, deg+ (u) = 0

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 45


Handshaking Theorem (CO4)
Handshaking Theorem
Handshaking theorem states that the sum of degrees of all the vertices of a
graph is twice the number of edges. If G=(V,E) be a undirected graph with
E edges, then-
Σ deg G(V) = 2E
Proof-
Since the degree of a vertex is the number of edges incident with that
vertex, the sum of degree counts the total number of times an edge is
incident with a vertex. Since every edge is incident with exactly two
vertices, each edge gets counted twice once at each end. Thus the sum of the
degrees is equal twice the number of edges.
This theorem applies even if multiple edges and loops are present. The
theorem holds this rule that if several people shake hands, the total number
of hands shake must be even that is why the theorem is
called handshaking theorem.
07/02/24 46
ANAMIKA TIWARI Discrete Structures Unit 5
Summary of Graph Types(CO5)

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 47


Simple graph – special case(CO 5)

Null Graph
A graph having no edges is called a Null Graph.

Trivial Graph
A graph with only one vertex is called a Trivial Graph.

Non-Directed Graph
A non-directed graph contains edges but the edges are not
directed ones.
07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 48
Simple graph – special case(CO 5)
Directed Graph
In a directed graph, each edge has a direction.

Simple Graph
A graph with no loops and no parallel edges is called a simple graph.
•The maximum number of edges possible in a simple graph with ‘n’ vertices
is nC2 where nC2 = n(n – 1)/2.
•The number of simple graphs possible with ‘n’ vertices = 2nc2 = 2n(n-1)/2.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 49


Simple graph – special case(CO 5)
Connected Graph
A graph G is said to be connected if there exists a path between every
pair of vertices.

Disconnected Graph
A graph G is disconnected, if it does not contain at least two connected
vertices.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 50


Simple graph – special case(CO 5)
Regular Graph
A graph G is said to be regular, if all its vertices have the same degree. In a
graph, if the degree of each vertex is ‘k’, then the graph is called a ‘k-regular
graph’.

A simple graph with ‘n’ mutual vertices is called a complete graph and it
is denoted by ‘Kn’. In the graph, a vertex should have edges with all other
vertices, then it called a complete graph.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 51


Simple graph – special case(CO 5)
Cycle Graph
A simple graph with ‘n’ vertices (n >= 3) and ‘n’ edges is called a cycle graph
if all its edges form a cycle of length ‘n’.
Notation − Cn

Acyclic Graph
A graph with no cycles is called an acyclic graph.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 52


Simple graph – special case(CO 5)

A wheel graph is obtained from a cycle graph Cn-1 by adding a new vertex.
That new vertex is called a Hub which is connected to all the vertices of
Cn.
Notation − Wn
No. of edges in Wn = No. of edges from hub to all other vertices +
No. of edges from all other nodes in cycle graph without a hub.
= (n–1) + (n–1)
= 2(n–1)

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 53


Bipartite graphs(CO 5)

A bipartite graph, also called a bi-graph, is a set of graph vertices decomposed into
two disjoint sets such that no two graph vertices within the same set are adjacent.
A bipartite graph is a special case of a k-partite graph with k=2 .

The illustration above shows some bipartite graphs, with vertices in each graph
colored based on to which of the two disjoint sets they belong.
Bipartite graphs are equivalent to two-colorable graphs. All acyclic graphs are
bipartite. A cyclic graph is bipartite iff all its cycles are of even length

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 54


Complete bipartite graph Km,n(CO 5)

 A bipartite graph is the complete bipartite graph Km,n if every vertex in


V(G1) is joined to a vertex in V(G2) and
conversely,
 |V(G1)| = m

 |V(G2)| = n

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 55


Representation of Graphs(CO5)

Incidence (Matrix): Most useful when information about edges is


more desirable than information about vertices.

Adjacency (Matrix/List): Most useful when information about the


vertices is more desirable than information about the edges. These
two representations are also most popular since information about the
vertices is often more desirable than edges in most applications.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 56


Representation- Incidence Matrix(CO5)

 G = (V, E) be an unditected graph. Suppose that v 1, v2, v3, …, vn are the


vertices and e1, e2, …, em are the edges of G. Then the incidence matrix
with respect to this ordering of V and E is the n x m matrix M = [m ij],
where 1 when edge ej is incident with vi
m ij  
0 otherwise

Can also be used to represent :


Multiple edges: by using columns with identical entries, since these
edges are incident with the same pair of vertices
Loops: by using a column with exactly one entry equal to 1,
corresponding to the vertex that is incident with the loop

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 57


Representation-Incidence matrix(CO5)

• Representation Example: G = (V, E)

u e1 e2 e3
e1 e2 v 1 0 1
u 1 1 0
v w
e3 w 0 1 1

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 58


Representation- Adjacency Matrix(CO5)

 There is an N x N matrix, where |V| = N , the Adjacenct Matrix (NxN) A =


[aij]

For undirected graph 1 if {vi, vj} is an edge of G


a ij  
0 otherwise

For directed graph


1 if (vi, vj) is an directed edge from Vi to Vj of G
a ij  
0 otherwise

This makes it easier to find sub-graphs, and to reverse graphs if needed.


07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 59
Representation-Adjacency matrix(CO5)

• Representation of undirected graph G = (V, E)

v u w
v w v 0 1 1
u 1 0 1
w 1 1 0

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 60


Representation-Adjacency matrix(CO5)

• Representation of directed graph G = (V, E)

v u w
u v 0 1 0
u 0 0 1
v w w 1 0 0

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 61


Representation-Adjacency list (CO5)

• Each node (vertex) has a list of which nodes (vertex) it is adjacent


• Representation of undirected graph G = (V, E)

u node Adjacency List

u v,w

v w v w, u
w u,v

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 62


Graph - Isomorphism(CO5)
• A graph can exist in different forms having the same number of
vertices, edges, and also the same edge connectivity. Such graphs
can isomorphic graphs.
• Two graphs G1 and G2 are said to be isomorphic if −
• Their number of components (vertices and edges) are same.
• Their edge connectivity is retained.
• There exists a function ‘f’ from vertices of G1 to vertices of G2 [f:
V(G1) ⇒ V(G2)], such that
• Case (i): f is a bijection (both one-one and onto)
• Case (ii): f preserves adjacency of vertices, i.e., if the edge {U, V} ∈
G1, then the edge {f(U), f(V)} ∈ G2, then G1 ≡ G2.
• Application Example: In chemistry, to find if two compounds have the
same structure

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 63


Graph - Isomorphism(CO5)

• If G1 ≡ G2 then −
|V(G1)| = |V(G2)|
|E(G1)| = |E(G2)|
• Degree sequences of G1 and G2 are same.
If the vertices {V1, V2, .. Vk} form a cycle of length K in G1, then the vertices {f(V1),
f(V2),… f(Vk)} should form a cycle of length K in G2.

• All the above conditions are necessary for the graphs G 1 and G2 to be
isomorphic, but not sufficient to prove that the graphs are isomorphic.
• (G1 ≡ G2) if and only if (G1− ≡ G2−) where G1 and G2 are simple graphs.
• (G1 ≡ G2) if the adjacency matrices of G1 and G2 are same.
• (G1 ≡ G2) if and only if the corresponding subgraphs of G 1 and G2 (obtained by
deleting some vertices in G1 and their images in graph G 2) are isomorphic.
07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 64
Graph - Isomorphism(CO5)

•In the graph G3, vertex ‘w’ has only degree 3, whereas all the other graph
vertices has degree 2. Hence G3 not isomorphic to G 1 or G2.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 65


Graph - Homomorphism(CO5)
A homomorphism from a graph G to a graph H is a mapping (May not be a
bijective mapping) h: G → H such that − (x, y) ∈ E(G) → (h(x), h(y)) ∈
E(H). It maps adjacent vertices of graph G to the adjacent vertices of the
graph H.
OR. G’ is said to be homomorphic to G if G’ is obtained from G by dividing
edges and adding vertex in G.
Properties of Homomorphisms

•A homomorphism is an isomorphism if it is a bijective mapping.


•Homomorphism always preserves edges and connectedness of a graph.
•The compositions of homomorphisms are also homomorphisms.
•To find out if there exists any homomorphic graph of another graph is a
NPcomplete problem.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 66


Connectivity in Graph (CO5)
• Basic idea of connectivity: In a Graph reachability among vertices can
be acheived by traversing the edges
Application Example:
- In a city to city road-network, if one city can be reached from another
city.
- Problems if determining whether a message can be sent between two
computer using intermediate links
- Efficiently planning routes for data delivery in the Internet

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 67


Connectivity in Graph (CO4)
• A graph is connected if every pair of vertices can be connected by a path.
• A connected graph is an undirected graph in which every unordered pair of
vertices in the graph is connected. Otherwise, it is called a disconnected
graph.
• Each connected subgraph of a non- connected graph G is called a
component of G.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 68


Paths and cycles in Graph (CO 5)
 Walk: It is a finite alternating sequence of vertices and edges, beginning and
ending with vertices such that each edge is incident with vertices preceding
and following it.
 No edge should appear more than one in a walk, however a vertex can
appear.
 Closed Walk: When a walk begin and ends with same vertex.
 Path: A open walk in which no vertex appears more than one is called path.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 69


Topic objective : Euler Graph(CO5)

• Eulerian graphs will be used to solve many practical problems like


Konisberg Bridge problem.
• They can also be used to by mail carriers who want to have a route
where they don’t retrace any of their previous steps.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 70


Euler- Definitions(CO5)
• An Eulerian path (Eulerian trail) in a graph is a path that uses each
edge precisely once. If such a path exists, the graph is called
traversable.

• An Eulerian cycle (Eulerian circuit, Euler tour) in a graph is a


closed walk that uses each edge precisely once. If such a cycle exists,
the graph is called Eulerian (also unicursal).

• Representation example: G1 has Euler path a, c, d, e, b, d, a, b

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 71


Euler Circuit(CO5)

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 72


Euler Theorem1(CO5)
1. A connected graph G is Eulerian if and only if G is connected and
has no vertices of odd degree.
Building a simple path:
{a,b}, {b,c}, {c,f}, {f,a}

Euler circuit constructed if all edges


are used. True here?

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 73


Euler Theorem2 (CO5)
• A connected graph G is has an Euler trail from node a to some other
node b if and only if G is connected and a  b are the only two nodes
of odd degree.
• Assume G has an Euler trail T from node a to node b (a and b not
necessarily distinct).
• For every node besides a and b, T uses an edge to exit for each edge
it uses to enter. Thus, the degree of the node is even.

1. If a = b, then a also has even degree.  Euler circuit

2. If a  b, then a and b both can have odd degree.  Euler path

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 74


Eulerian Graphs(CO5)
A and E are Eulerian Graphs.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 75


Topic objective: Hamiltonian Graph(CO5)

•It will be used in various fields such as Computer Graphics, electronic


circuit design, mapping genomes, and operations research.
•To plan bus route to pick up students (node->student, road-> edges, bus
path-> Hamiltonian path)
•To combine many tiny fragments of genetic code in genome mapping.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 76


Hamiltonian Graph(CO5)
• Hamiltonian path (also called traceable path) is a path that visits
each vertex exactly once.

• A Hamiltonian cycle (also called Hamiltonian circuit, vertex tour or


graph cycle) is a cycle that visits each vertex exactly once (except for
the starting vertex, which is visited once at the start and once again at
the end).

• A graph that contains a Hamiltonian path is called a traceable graph.


A graph that contains a Hamiltonian cycle is called a Hamiltonian
graph. Any Hamiltonian cycle can be converted to a Hamiltonian
path by removing one of its edges, but a Hamiltonian path can be
extended to Hamiltonian cycle only if its endpoints are adjacent.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 77


Hamiltonian Circuit(CO5)

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 78


Hamiltonian Graph(CO5)
C, D and F are a Hamiltonian Graphs.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 79


Hamiltonian Graph Theorems(CO5)
• DIRAC’S Theorem: if G is a simple graph with n vertices with n ≥ 3
such that the degree of every vertex in G is at least n/2 then G has a
Hamilton circuit.

• ORE’S Theorem: if G is a simple graph with n vertices with n ≥ 3


such that deg (u) + deg (v) ≥ n for every pair of nonadjacent vertices u
and v in G, then G has a Hamilton circuit.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 80


Topic objective: Planar Graphs(CO4)
To design or to provide a solution for a graph structure in which
crossing edges are a nuisance, including design problems for circuits,
subways, utility lines.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 81


Planar Graphs(CO5)
A graph (or multigraph) G is called planar if G can be drawn in the
plane with its edges intersecting only at vertices of G, such a
drawing of G is called an embedding of G in the plane.

Application Example: VLSI design (overlapping edges requires


extra layers), Circuit design (cannot overlap wires on board)
Representation examples: K1,K2,K3,K4 are planar, Kn for n>4 are
non-planar

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 82


Planar Graphs(CO5)

• Representation example

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 83


Planar Graphs(CO5)

• Representation examples: K3,3 is Non-planar

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 84


Topic objective: Graph coloring(CO5)
• It will be used for making Schedule or Time Table.
• Register Allocation: assigning a large number of target program
variables onto a small number of CPU registers
• Mobile Radio Frequency Assignment: every tower represents a vertex
and an edge between two towers represents that they are in range of
each other.
• Sudoku: There is an edge between two vertices if they are in same row
or same column or same block.
• It will check if a graph is Bipartite or not by coloring the graph using
two colors

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 85


Graph coloring(CO5)
• Graph coloring is an assignment of "colors", almost always taken to
be consecutive integers starting from 1 without loss of generality, to
certain objects in a graph. Such objects can be vertices, edges, faces, or
a mixture of the above.
• Vertex coloring is the most common graph coloring problem. The
problem is, given m colors, find a way of coloring the vertices of a
graph such that no two adjacent vertices are colored using same color.

• Application examples: scheduling, register allocation in a


microprocessor, frequency assignment in mobile radios, and pattern
matching.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 86


Vertex Coloring Problem(CO5)

• Assignment of colors to the vertices of the graph such that proper


coloring takes place (no two adjacent vertices are assigned the same
color)
• Chromatic number: least number of colors needed to color the graph
• A graph that can be assigned a (proper) k-coloring is k-colorable, and
it is k-chromatic if its chromatic number is exactly k.

3-chromatic

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 87


Vertex Coloring Problem(CO5)

• The problem of finding a minimum coloring of a graph is NP-Hard


• The corresponding decision problem (Is there a coloring which uses at
most k colors?) is NP-complete
• The chromatic number for Cn = 3 (n is odd) or 2 (n is even), Cn = n, Km,n
=2
• Cn: cycle with n vertices; Kn: fully connected graph with n vertices;
Km,n: complete bipartite graph

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 88


The Four color theorem(CO5)
• the Four color theorem, or the four color map theorem, states that,
given any separation of a plane into contiguous regions, producing a
figure called a map, no more than four colors are required to color the
regions of the map so that no two adjacent regions have the same color
• The Four color theorem: the chromatic number of a planar graph is no
greater than 4
• Example: G1 chromatic number = 3, G2 chromatic number = 4
• (Most proofs rely on case by case analysis).

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 89


Daily Quiz(CO 5)
1. For which of the following combinations of the degrees of vertices would the connected
graph be eulerian?
a) 1,2,3 b) 2,3,4
c) 2,4,5 d) 1,3,5
2. A graph with all vertices having equal degree is known as a __________
a) Multi Graph b) Regular Graph
c) Simple Graph d) Complete Graph
3. Which of the following ways can be used to represent a graph?
a) Adjacency List and Adjacency Matrix
b) Incidence Matrix
c) Adjacency List, Adjacency Matrix as well as Incidence Matrix
d) No way to represent
4. Consider an undirected random graph of eight vertices. The probability that there is an
edge between a pair of vertices is 1/2. What is the expected number of unordered cycles of
length three?
a) 1/8 b)1
c) 7 d)8

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 90


Daily Quiz(CO 5)
5. A graph is a collection of.... ?
a) Row and columns b) Vertices and edges
c) Equations d) None of these

6. The degree of any vertex of graph is .... ?


a) The number of edges incident with vertex
b) Number of vertex in a graph
c) Number of vertices adjacent to that vertex
d) Number of edges in a graph

7. A graph with no edges is known as empty graph. Empty graph is also known as... ?
a) Trivial graph
b) Regular graph
c) Bipartite graph
d) None of these

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 91


Daily Quiz(CO 5)
8. If the origin and terminus of a walk are same, the walk is known as... ?
a) Open b) Closed
c) Path d) None of these

9. Radius of a graph, denoted by rad(G) is defined by.... ?


a) max {e(v): v belongs to V }
b) min { e(v): v belongs to V}
c) max { d(u,v): u belongs to v, u does not equal to v }
d) min { d(u,v): u belongs to v, u does not equal to v }

10. A graph G is called a ..... if it is a connected acyclic graph


a) Cyclic graph b) Regular graph
c) Tree d) Not a graph

11. A graph is a collection of


a) Row and columns b) Vertices and edges
c) Equations d) None of these

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 92


Daily Quiz(CO 5)
12. How many relations are there on a set with n elements that are symmetric and a set with n
elements that are reflexive and symmetric ?
a) 2n(n+1)/2 and 2n.3n(n–1)/2
b) 3n(n–1)/2 and 2n(n–1)
c) 2n(n+1)/2 and 3n(n–1)/2
d) 2n(n+1)/2 and 2n(n–1)/2

13. In a graph if e=(u, v) means


a) u is adjacent to v but v is not adjacent to u
b)e begins at u and ends at v
c) u is processor and v is successor
d) both b and c

14. A minimal spanning tree of a graph G is


a) A spanning sub graph
b) A tree
c) Minimum weights
d) All of above

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 93


Weekly Assignment(CO 5)

Q1.Explain different type of graph with example.


Q2.Explain different terminology of graph with example
Q3. Define incidence and adjacency matrix of graph with example.
Q4.Explain graph and digraph with example.
Q5. Explain planar graph with example.
Q6.Explain Euler circuit and Euler path.
Q7. what is isomorphic graph.
Q8.Explain chromatic number .
Q9. For the expression (7-(4*5))+(9/3) which of the following is the post order tree traversal?
Q10. Define planar graph. Prove that for any connected planar graph, v – e+ r = 2 Where v, e, r is the
number of vertices, edges, and regions of the graph respectively.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 94


Faculty Video Links, Youtube & NPTEL Video Links and
Online Courses Details (CO 5)
Youtube/other Video Links:
• https://www.youtube.com/watch?v=Dsi7x-
A89Mw&list=PL0862D1A94725 2D20&index=28
• https://www.youtube.com/watch?
v=74l6t4_4pDg&list=PL0862D1A947252D20&index=29
• https://www.youtube.com/watch?
v=4d2XEn1j_q4&list=PL0862D1A947252D20&index=30
• https://www.youtube.com/watch?
v=qvw1GX93JSY&list=PL0862D1A947252D20&index=32
• https://www.youtube.com/watch?
v=ImLM1Vsr35c&list=PL0862D1A947252D20&index=33

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 95


MCQs(CO 5)

Q1. Which of the following statements for a simple graph is correct?


a) Every path is a trail
b) Every trail is a path
c) Every trail is a path as well as every path is a trail
d) Path and trail have no relation
Q2. What is the number of edges present in a complete graph
having n vertices?
a) (n*(n+1))/2
b) (n*(n-1))/2
c) n
d) Information given is insufficient
Q3. In a simple graph, the number of edges is equal to twice
the sum of the degrees of the vertices.
a) True
b) False

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 96


MCQs(CO 5)
Q4. A connected planar graph having 6 vertices, 7 edges contains_____________ regions.
a) 15 b) 3
c) 1 d) 11

Q5. If a simple graph G, contains n vertices and m edges, the number of edges in the Graph
G'(Complement of G) is ___________
a) (n*n-n-2*m)/2 b)(n*n+n+2*m)/2
c) (n*n-n-2*m)/2 d) (n*n n+2*m)/2

Q6. Which of the following properties does a simple graph not hold?
a) Must be connected b) Must be unweighted
c) Must have no loops or multiple edges d) Must have no multiple edges

Q7. What is the maximum number of edges in a bipartite graph having 10 vertices?
a) 24 b) 21
c) 25 d) 16

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 97


MCQs(CO 5)
Q8 An undirected graph G which is connected and acyclic is called ____________
a) bipartite graph
b) cyclic graph
c) tree
d) forest

Q9. An n-vertex graph has ______ edges.


a) n2
b) n-1
c) n*n
d) n*(n+1)/2

Q10. The tree elements are called __________


a) vertices
b) nodes
c) points
d) edges

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 98


MCQs(CO 5)
Q11. What is a bipartite graph?
a) a graph which contains only one cycle
b) a graph which consists of more than 3 number of vertices
c) a graph which has odd number of vertices and even number of edges
d) a graph which contains no cycles of odd length

Q12. How many cycles are there in a wheel graph of order 5?


a) 6
b) 10
c) 25
d) 7

Q13. The time complexity to find a Eulerian path in a graph of vertex V and edge E is
_____________
a) O(V2)
b) O(V+E-1)
c) O(V+E)
d) O(E+1)

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 99


MCQs(CO 5)
Q14. In preorder traversal of a binary tree the second step is ____________
a) traverse the right subtree
b) traverse the left subtree
c) traverse right subtree and visit the root
d) visit the root

Q15. What is the minimum height for a binary search tree with 60 nodes?
a) 1
b) 3
c) 4
d) 2

Q16. For the expression (7-(4*5))+(9/3) which of the following is the post order tree traversal?
a) *745-93/+
b) 93/+745*-
c) 745*-93/+
d) 74*+593/-

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 100


GLOSSARY QUESTION (CO5)

1. n-vertex graph has edges 1. directed acyclic graph


2. undirected graph G which is connected and acyclic 2. tree
3. polytree is called 3. n-1
4. The tree elements are called 4. nodes
5. an n-ary tree, each vertex has at most children 5. n

6. graph which consists of disjoint union of trees is called 6. 360


7. 7-node directed cyclic graph, the number of Hamiltonian cycle 7. forest
8. G has degree at most 23 then G can have a vertex colouring of 8. bipartite graph
9. the vertex set and the edge set are finite sets 9. 24
10. A Tree is a connected 10. acyclic undirected
graph
ANAMIKA TIWARI Discrete
07/02/24 101
Structures Unit 5
Old Question Papers(CO 5)

Q1 Construct a binary tree from the given two Travels (IGDTUW, 2020)
In order 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
Post order 1, 4, 3, 2, 6, 8, 9, 11, 10, 7, 5
Q2 Define Hamiltonian graph with suitable example. (Anna Univ, 2017)
Q3 Define planar graph. Prove that for any connected planar graph, v – e+ r = 2 Where v, e, r
is the number of vertices, edges, and regions of the graph respectively. (AKTU, 2017)
Q4. What are different ways to represent a graph. Define Euler circuit and Euler graph. Give
necessary and sufficient conditions for Euler circuits and paths. (KTU,2017)
Q5. For the expression (7-(4*5))+(9/3) which of the following is the post order tree traversal?
Q6. What are application of a Depth First Search traversal ? (Anna Univ, 2017)
Q7. What is the Worst case complexity of Breadth First Search traversal ? (NIET Autonomous,
2021)
Q8. What are the applications of Breadth First Search traversal? (KTU, 2017)
For more Previous year Question papers:
https://drive.google.com/drive/folders/1xmt08wjuxu71WAmO9Gxj2iDQ0lQf-so1

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 102


Expected Questions for Exam(CO 5)

Q1. Define Hamiltonian graph with suitable example


Q2. Define planar graph. Prove that for any connected planar graph, v – e+ r = 2 Where v, e, r
is the number of vertices, edges, and regions of the graph respectively.
Q3. What are different ways to represent a graph. Define Euler circuit and Euler graph. Give
necessary and sufficient conditions for Euler circuits and paths
Q4.Construct a binary tree from the given two Travels
In order 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
Post order 1, 4, 3, 2, 6, 8, 9, 11, 10, 7,
Q5. For the expression (7-(4*5))+(9/3) which of the following is the post order tree traversal?
Q6. What are application of a Depth First Search traversal ?
Q7. What is the Worst case complexity of Breadth First Search traversal ?
Q8. What are the applications of Breadth First Search traversal?
Q9. For the expression (7-(4*5))+(9/3) which of the following is the post order tree traversal?

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 103


RECAP OF UNIT (CO5)

• Tree Terminology
• A tree is a hierarchical data structure defined as a collection of nodes. Nodes represent value and nodes are
connected by edges. A tree has the following properties:
• The tree has one node called root. The tree originates from this, and hence it does not have any parent.
• Each node has one parent only but can have multiple children.
• Each node is connected to its children via edge.
• Binary Tree: In a Binary tree, every node can have at most 2 children, left and right. In diagram below, B &
D are left children and C, E & F are right children.

• Balanced Tree: If the height of the left and right subtree at any node differs at most by 1, then the tree is
called a balanced tree.
• GRAPH- In discrete mathematics, a graph is a collection of points, called vertices, and lines between
those points, called edges.

ANAMIKA TIWARI Discrete


07/02/24 104
Structures Unit 5
RECAP OF UNIT (CO5)

•The concept of graphs in graph theory stands up on some basic terms such
as point, line, vertex, edge, degree of vertices, properties of graphs, etc.
•Graph theory has several application in real world.
•Graph theory used in Computer networks to minimize the cost and time of
delivery of data.
•To distinguish between two chemical compounds with the same molecular
formula but different structures.
• To solve shortest path problems between cities.
•To schedule exams and assign channels to television stations.

07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 105


07/02/24 ANAMIKA TIWARI Discrete Structures Unit 5 106

You might also like