Professional Documents
Culture Documents
Topic 6
Topic 6
Topic 6
For example
Connected and Disconnected graphs
● A connected graph is a graph in which there is a path between every pair of vertices. In
other words, for any two vertices in a connected graph, there exists a sequence of edges
that connects them.
● Disconnected graph is a graph that is not connected. In a disconnected graph, there are
isolated subsets of vertices that have no connection to other subsets.
● For example
Weighted and Unweighted graphs
● A weighted graph is a graph in which each edge is assigned a numerical value called a
weight. The weight represents some kind of measurement or cost associated with
traversing or using that particular edge.
● The weights can represent various quantities depending on the context of the problem.
For example, in a transportation network, the weights may represent the distances between
cities or the travel time required to move from one location to another.
Weighted and Unweighted graphs
● The graph is a unweighted type if every edge does not have an associated numerical
value or weight.
● In an unweighted graph, all edges are considered to have the same cost or weight,
typically indicating a simple presence or absence of a connection.
For example,
Subgraph
● The graph H is said to be a subgraph of G , if and only if every vertex in H is also a
vertex in G, every edge in H is also an edge in G.
● A subgraph is like a smaller version of the original graph, containing a subset of its
vertices and edges.
For example,
Exercise
Find the at least three possible subgraphs for following graphs 𝑮𝟏 and 𝑮𝟐
𝑮𝟏 𝑮𝟐
Types of graph
a) Simple graph
b) Multi graph
c) Pseudo graph
Types of graph
Simple graph
● It is an undirected graph that does not contain any loops or multiple edges.
Note: Loop is an edge that connects a vertex to itself.
Multiple edges are the edges that connects same pair of vertex
● In a simple graph, the edges represent connections between pairs of vertices, and each
edge is unique. That is, there is at most one edge between any two vertices.
For example
Types of graph
Multi graph
● A multigraph graph is graph that has multiple edges between pair of vertices.
● The multigraph does not have any loops.
For example,
Types of graph
Pseudo graph
● A pseudo graph is graph that has multiple edges between pairs of vertices or loops, or
both.
● In pseudo graph both loops and multiple edges are allowed .
For example
Exercise
Classify the following graphs as simple graph, multigraph and pseudo graph
𝑮𝟏
𝑮𝟐 𝑮𝟑
Definitions and Terminologies in Graph theory
Incidence between edges and vertices
● An incident edge refers to an edge that is directly connected to a vertex in a graph.
Then the edge said to be incident to that vertex.
● An incident vertex refers to a vertex that is directly connected to an edge. Then the
vertex is said to be incident to that edges.
For example,
Degree of vertex
● The degree of a vertex in a graph refers to the number of edges incident to that vertex.
In other words, it represents the number of connections that a vertex has with other
vertices in the graph.
● It is denoted by 𝑑(𝑉)
Note: A vertex with loop has a degree of two.
● The degree of a graph is defined as the maximum degree among all vertices in the
graph.
For Example,
𝑑 1 =1 𝑑 2 =2 𝑑 5 =5 𝑑 0 =0
The degree of 𝑑 𝑮𝟏 = 5
𝑮𝟏
Examples
Exercise
Draw any undirected graph with degree 2, 5, and 6
Handshaking theorem
Let 𝐺 = (𝑉, 𝐸) be the undirected graph, then sum of the degrees of all the vertices is equals to
twice the number of edges present in the graph.
For example,
𝑮𝟏
𝑮𝟐
Special types of graphs
Special types of graphs are ,
a) Complete graph
b) Cycle graph
c) Bipartite graph
Special types of graphs
Complete graph
● A graph in which each vertex is connected to every other vertex is called a complete graph.
● If complete graph has 𝑛 number of vertices, then the number of edges is
(𝑛 × (𝑛 − 1)) / 2.
● It is denoted by 𝐾𝑛 , where 𝑛 is number of vertices.
For example,
𝑲𝟑 𝑲𝟓
Special types of graphs
Circle graph
● A circle graph is a simple graph that forms a closed loop or cycle. It consists of a single
cycle of vertices and edges, where each vertex is connected to its adjacent vertices, and the
last vertex is connected back to the first vertex, forming a circular shape.
● A circle graph should have minimum of three vertices with degree 2.
For example,
Bipartite graph
● A simple graph 𝐺 = 𝑉, 𝐸 is called bipartite graph if vertex 𝑉 can be divided into two sets
of vertices 𝑣1 and 𝑣2 in such a way that vertices of set 𝑣1 only joins the vertices of set 𝑣2 .
● In the bipartite graph none of the vertices belonging to the same set join each other.
● It is denoted by 𝐺 = 𝑣1 , 𝑣2 , 𝐸
For example,
𝑣1 = 1,2,3,4,5
𝑣2 = {𝐴, 𝐵, 𝐶, 𝐸}
Example
Check whether the following graph is a bipartite graph or not. If it is a bipartite graph, then
find two sets of vertices
Exercise
Check whether the following graph is a bipartite graph or not. If it bipartite graph, then find
two sets of vertices
Complete Bipartite graph
● A bipartite graph 𝐺 = 𝑣1 , 𝑣2 , 𝐸 is said to be complete bipartite graph if every vertices in
𝑣1 is adjacent to 𝑣2 or every vertices in 𝑣2 is adjacent to 𝑣1 .
● If 𝐺 = 𝑣1 , 𝑣2 , 𝐸 is a complete bipartite graph with 𝑣1 = 𝑚 and 𝑣2 = 𝑛 then 𝐺 =
𝑣1 , 𝑣2 , 𝐸 denoted by, 𝐾𝑚,𝑛
For example,
Exercise
1. Draw any 𝐾3,3 𝑎𝑛𝑑 𝐾3,4 bipartite graph
2. Draw any complete 𝐾1,3 𝑎𝑛𝑑 𝐾2,4 bipartite graph
Different types of routes
1. Walks
2. tails
3. paths
4. cycles
5. circuit
Different types of routes
Walk
A walk is a sequence of vertices and edges where each edge connects adjacent vertices.
The vertices and edges in a walk can be repeated.
For example,
𝒆𝟒
w1 = 𝒗𝟐 − 𝒆𝟑 − 𝒗𝟒 − 𝒆𝟒 − 𝒗𝟏 𝒆𝟑
𝒆𝟓 𝒆𝟔
w𝟐 = 𝒗𝟐 − 𝒆𝟏 − 𝒗𝟔 − 𝒆𝟗 − 𝒗𝟑 − 𝒆𝟕 − 𝒗𝟓 𝒆𝟏 𝒆𝟐
𝒆𝟕
𝒆𝟗
𝒆𝟖
Different types of routes
Different types of walks
Open walk: A walk is said to be an open walk if the starting and ending vertices are different.
Closed walk: A walk is said to be closed walk if the starting and ending vertices are identical.
For example,
(Open walk) 𝒆𝟒
𝒆𝟑
𝒘𝟏 = 𝒗𝟐 − 𝒆𝟑 − 𝒗𝟒 − 𝒆𝟒 − 𝒗𝟏
𝒆𝟓 𝒆𝟔
𝒆𝟐
(Closed walk) 𝒆𝟏
𝒘𝟐 = 𝒗𝟐 − 𝒆𝟏 − 𝒗𝟔 − 𝒆𝟗 − 𝒗𝟑 − 𝒆𝟐 − 𝒗𝟐 𝒆𝟕
𝒆𝟗
𝒆𝟖
Exercise
Find at least two closed walk and open walk for following graphs
Different types of routes
Tails
A tails is a walk in which no edges is repeated, but vertices can be repeated.
For example,
𝒆𝟒
Open tail 𝒆𝟑
1. 𝒕𝟏 = 𝒗𝟐 − 𝒆𝟏 − 𝒗𝟔 − 𝒆𝟗 − 𝒗𝟑 − 𝒆𝟕 − 𝒗𝟓
𝒆𝟓
Closed tail 𝒆𝟐
𝒆𝟔
𝒆𝟏
1. 𝒕𝟐 = 𝒗𝟐 − 𝒆𝟏 − 𝒗𝟔 − 𝒆𝟗 − 𝒗𝟑 − 𝒆𝟐 − 𝒗𝟐
𝒆𝟕
𝒆𝟗
𝒆𝟖
Different types of routes
Circuits
A circuit is a closed tail or closed walk where no edges are repeated.
In circuit, starting vertex and ending vertex should be same.
For example,
𝒆𝟒
𝒄𝟏 = 𝒗𝟐 − 𝒆𝟏 − 𝒗𝟔 − 𝒆𝟗 − 𝒗𝟑 − 𝒆𝟐 − 𝒗𝟐 𝒆𝟑
𝒄𝟐 = 𝒗𝟏 − 𝒆𝟒 − 𝒗𝟒 − 𝒆𝟒 − 𝒗𝟑 − 𝒆𝟔 − 𝒗𝟏
𝒆𝟓 𝒆𝟔
𝒆𝟏 𝒆𝟐
𝒆𝟕
𝒆𝟗
𝒆𝟖
Exercise
Find at least two circuits for following graphs
Different types of routes
Path
A path is a walk in which neither vertices nor edges are repeated.
In path,
● Vertices are not repeated except starting and ending vertex.
● Edges are not repeated
𝒆𝟒
𝒆𝟑
For example,
𝒑𝟏 = 𝒗𝟐 − 𝒆𝟏 − 𝒗𝟔 − 𝒆𝟗 − 𝒗𝟑 𝒆𝟓 𝒆𝟔
𝒆𝟏 𝒆𝟐
𝒑𝟐 = 𝒗𝟏 − 𝒆𝟒 − 𝒗𝟒 − 𝒆𝟓 − 𝒗𝟑
𝒆𝟕
𝒆𝟗
𝒆𝟖
Different types of routes
Cycle
A cycle is a closed path, where the starting and ending vertices are the same, and all other
vertices are distinct. A cycle must have at least three vertices.
For example,
𝒄𝟏 = 𝑨 − 𝑩 – 𝑪 – 𝑨
𝒄𝟏 = 𝑯 − 𝑫 – 𝑩 – 𝑪– 𝑯
Exercise
Find the at least two path and cycle for following graph
Summary
The above definitions can be easily remembered with the help of following chart
Euler Circuits
Let 𝐺 = (𝑉, 𝐸) be the undirected and connected graph, if graph 𝐺 has a circuit such that it
traverse every edge in graph 𝐺 exactly once.
If graph has a Euler circuit, then graph is called as Eulerian Graph.
For example,
Euler circuit = 𝐴, 𝐷, 𝐸, 𝐴, 𝐶, 𝐸, 𝐹, 𝐶, 𝐵, 𝐴
Euler path
A Euler path is a path in a graph that traverses each edge exactly once. Unlike a Euler circuit,
which is a closed walk that starts and ends at the same vertex, a Euler path starts at one vertex
and ends at another.
Theorem: Graph 𝐺 has Euler path if and only if
➢ 𝐺 is connected
➢ A graph will contain a Euler path if it contains at most two vertices of odd degree.
For example,
Euler path = 𝟒, 𝟑, 𝟎, 𝟐, 𝟏, 𝟎
Euler path = 𝟎, 𝟏, 𝟐, 𝟎, 𝟑, 𝟒
Exercise
Find a Euler circuit and Euler path for following graph
Fleury's algorithm to find Euler circuit and path
Fleury's algorithm
● Start at any vertex if finding a Euler circuit. (If finding a Euler path, start at one of the two
vertices with old degree.)
● Select an arbitrary edge from the current vertex that has not been visited yet. If removing
the selected edge does not disconnect the graph, remove it from the graph and add it to the
Euler circuit or path.
● Move to the other endpoint of the selected edge and set it as the new current vertex.
● Repeat the step 2 until all the edges are visited.
Example
Find a Euler circuit and path using Fleury's algorithm
Example
Find a Euler circuit and Euler path for following graph using Fleury's algorithm
Hamiltonian cycle
A Hamiltonian cycle in connected graph G is a cycle that passes through every vertex of G
exactly once, except for the starting vertex, which is also the ending vertex. In other words, it is
a cycle that visits each vertex of the graph exactly once and returns to the starting vertex.
Theorem: Graph 𝐺 has Hamilton cycle if and only if
➢ 𝐺 is connected
➢ All vertices of graph have minimum of degree 2
➢ Graph does not contain any articulation point
Note: An articulation point, also known as a cut vertex, is a vertex in a graph whose
removal disconnects the graph into two or more separate components
A graph which contains Hamilton cycle is called as Hamiltonian graph.
Hamiltonian cycle
For example,
Hamiltonian cycle = 𝐴, 𝐵, 𝐶, 𝐷, 𝐸, 𝐹, 𝐴
Hamiltonian cycle = 𝐹, 𝐸, 𝐷, 𝐶, 𝐵, 𝐴, 𝐹
𝑮𝟏
Graph 𝑮𝟐 is example of Non-Hamilton graph.
𝑮𝟐
Exercise
Determine whether the graph below is Hamiltonian graph or not. If it is, find a Hamilton cycle.
If it not explain why?
Graph coloring
A colouring of a graph is the assignment of a colour to each vertex of the graph so that no two
adjacent vertices are assigned the same colour.
Chromatic number
The minimum numbers of colors required to colour all the vertices of the given graph is called
as chromatic number. It is dented by 𝑥(𝐺).
For example,
𝑥 𝑮𝟏 = 4
𝑥 𝑮𝟐 = 2
𝑮𝟏 𝑮𝟐
Exercise
1. Find the chromatic number of following graph
2 . Consider a graph with 7 vertices and the following edges: {(1, 2), (1, 3), (2, 3), (2, 4), (3, 4),
(4, 5), (5, 6), (5, 7), (6, 7)}. Determine the minimum number of colors required to color the
graph.
Tree
A simple graph is said to be the tree when it is connected and acyclic. (It does not contain any
cycle)
It is denoted by T.
For example,
𝑻𝟏 𝑻𝟐
For example,
The node / Vertex 1 is called as root of the tree
Terminologies in rooted tree
Parent and Child:
In a rooted tree, each node has a parent except for the root node. The parent node is the
immediate predecessor of a given node, and the child node are the immediate successors of a
given node.
Sibling:
In a tree, sibling nodes are nodes that share the same parent. They are at the same level of the
tree.
Ancestor and Descendant:
In a rooted tree, an ancestor of a given node is any node on the path from the root to that
node. A descendant of a given node is any node that can be reached by following edges from
that node.
Terminologies in rooted tree
Example:
Node 1 is parent for all other nodes.
Node 5 and 11 are children of node 6
For example,
The node D, E and F are external node
𝑻𝟏 𝑻𝟐
Terminologies in rooted tree
Subtree
A subtree is a subset of a tree that is also a tree. It consists of a node and all its descendants.
𝑻𝟏 𝑻𝟐
Exercise
Find the subtrees of following tree
Terminologies in rooted tree
Level`/ Depth
The depth or level of a node is the number of edges from the root to that node. The root node
is at level 0.
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.
Height:
• Total number of edges that lies on the longest path from any leaf node to a particular node
is called as height of that node.
• Height of a tree is the height of root node.
• Height of all leaf nodes = 0
Terminologies in rooted tree
Example
Exercise
Based on rooted tree,
1. Find the children of node 𝑗, 𝑛, 𝑜, 𝑝
2. Find the ancestors of node 𝑠, 𝑖 𝑎𝑛𝑑 𝑘
3. Find the sibling of node 𝑞, 𝑟 , 𝑠 𝑎𝑛𝑑 𝑡
4. Find the number of leaves in the rooted tree
5. Find the all the binary tree
6. Find the subtree keeping node b as root.
7. Find the height of rooted tree
Tree transversal
Procedure for systematically visiting every vertex of an ordered tree are called transversal
algorithms. There are three standard ways of traversing a rooted tree.
Depth-First Traversal (DFS):
1. Pre-order
2. In-order
3. Post- order
Pre-order
Pre-order
Def: Let 𝑇 be an ordered rooted tree with root 𝑟. If 𝑇 consists only 𝑟, then 𝑟 is the pre-order
transversal of 𝑇. Otherwise, if If 𝑇 consists subtrees of 𝑇1 , 𝑇2 … . . 𝑇𝑛 at 𝑟 from left to right.
Then the pre-order transversal begins by visiting 𝑟 and continues by traversing 𝑇1 , 𝑇2 till 𝑇𝑛
1. Visit the root 𝑟
2. Transverse the left subtree of 𝑟 in pre-order
3. Transverse the right subtree of 𝑟 in pre-order
Pre-order Example
In-order
In-order
Def: Let 𝑇 be an ordered rooted tree with root 𝑟. If 𝑇 consists only 𝑟, then 𝑟 is the in-order
transversal of 𝑇. Otherwise, if If 𝑇 consists subtrees of 𝑇1 , 𝑇2 … . . 𝑇𝑛 at 𝑟 from left to right.
Then the in-order transversal begins by traversing 𝑇1 in order, then traversing 𝑟. It continues
by traversing 𝑇2 in order, till 𝑇𝑛 .
𝑻𝟏 𝑻𝟐
Minimum Spanning tree
A minimum spanning tree (MST) is a spanning tree of a connected, weighted graph where the
sum of the weights of its edges is minimized.
It is a spanning tree that has the minimum possible total weight among all possible spanning
trees of the graph.
For example,
Minimum Spanning tree Algorithms
Minimum spanning tree (MST) algorithms are used to find the minimum cost spanning tree
in a weighted graph.
Two popular algorithms for finding the MST are:
a) Kruskal’s Algorithm
b) Prim's Algorithm
Minimum Spanning tree Algorithms
Kruskal’s Algorithm
Step 1: Remove the loops and multiple edges comparing the weight (Keep the minimum)
Step 2: Arrange the edges in the increasing order of their weights.
Step 3: Select edge which have minimum weight from the list and add it to the spanning tree if
inclusion of the edge does not form a circuit. If selected edge makes a circuit, then remove it
from list.
Step 4: Repeat the step 3 until all the vertices are connected.
Minimum Spanning tree Algorithms
Example
Minimum Spanning tree Algorithms
Find the minimum spanning tree in following graph using Kruskal’s Algorithm
Minimum Spanning tree Algorithms
Prim’s Algorithm
Step 1: Remove the loops and multiple edges comparing the weight (Keep the minimum)
Step 3: while Adding new, select the edges with minimum weight out of the edges from
Step 4: Repeat the step 3 until all the vertices are included and minimum spanning tree is
obtained
Example
Example
Find the minimum spanning tree using Prim's algorithms for following graphs