SlideShare a Scribd company logo
KONGUNADU COLLEGE OF ENGINEERING AND
TECHNOLOGY
DEPARTMENT OF INFORMATION TECHNOLOGY
20CS301 - DATA STRUCTURES
Subject Handled by
Mr.R.V.Viswanathan,AP / IT
KNCET.
NON LINEAR DATA
STRUCTURES - GRAPHS
UNIT - IV
Unit – IV Graphs
Definitions — Topological Sort — Shortest-Path
Algorithms — Dijkstra's Algorithm Minimum
Spanning Tree — Prim's algorithms — Depth-First
Traversal — Biconnectivity Euler circuits —
Applications of graphs.
GRAPHS
Graphs are data structures used to represent "connections"
between pairs of elements.
These elements are called nodes. They represent real-life objects,
persons, or entities.
The connections between nodes are called edges.
EXAMPLE APPLICATION
example, we could use graphs to model a transportation network where nodes would
represent facilities that send or receive products and edges would represent roads or
paths that connect them
WEIGHTED GRAPHS
A weight graph is a graph whose edges have a "weight" or "cost". The weight of an
edge can represent distance, time, or anything that models the "connection" between
the pair of nodes it connects.
INTRODUCTION TO GRAPH
A Graph is a non linear data structure consisting of nodes and edges.
The nodes are sometimes also referred to as vertices and the edges are
lines or arcs that connect any two nodes in the graph.
Generally, a graph G is represented as G=(V,E) where V is set of vertices
and E is set of edges.
In this Graph, the set of vertices
V = {0,1,2,3,4} and the set of edges
E ={01, 12, 23, 34, 04, 14, 13}.
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
APPLICATIONS
Graphs are used to solve many real life problems.
Graphs are used to represent networks.
The networks may include paths in a city or telephone network or circuit
network.
Graphs are also used in social networks like linkedIn , Facebook.
For example, in Facebook, each person is represented with a vertex(or
node).
Each node is a structure and contains information like person id, name,
gender, locale etc.
TYPES OF GRAPH
Directed Graph (or) Digraph
•Directed graph is a graph which consists of
directed edges, where each edge in E is
unidirectional.
•It is also referred as Digraph. If (v,w) is a
directed edge then (v,w) # (w,v)
Undirected Graph
•An undirected graph is a graph, which consists
of undirected edges. If (v,w) is an undirected
edge, then (v,w)=(w,v)
GRAPH TERMINOLOGIES
•A path is a sequence of vertices such that
there is an edge from each vertex to its
successor
•A path is simple if each vertex is distinct/A
path with no repeated vertices is called a
simple path
•A circuit is a path in which the terminal
vertex coincides with the initial vertex.
(Vertices may repeat but edges are not
allowed to repeat)
GRAPH TERMINOLOGIES
•Cycle: A circuit that doesn't repeat vertices is
called a Cycle. (Neither vertices except
possibly the starting and ending vertices) are
allowed to repeat, Nor edges are allowed to
repeat
•Self loop: If there is an edge whose starting
and end vertices are same, that is, (vi, vj) is
an edge, then it is called a self loop.
•Adjacent Vertices Two vertices are said to be
adjacent if there is an edge (arc) connecting
them.
0-1-2-3-0 - CYCLE
0-1-2-4-2-3- CIRCUIT
GRAPH TERMINOLOGIES
•Adjacent edges are edges that share a
common vertex.
•Degree of the Node A degree of a node is
the number of edges that are connected with
that node. A node with degree 0 is called as
isolated node.
 In degree: Number of edges entering a node
 Out degree: Number of edges leaving a node
 Degree = Indegree + Outdegree
•Connected and Disconnected
A graph G is said to be connected if there exists a path between every
pair of vertices.
A connected graph is the one in which some path exists between every two
vertices (u, v) in V.
There are no isolated nodes in connected graph.
UNCONNECTED/DisConnected GRAPH: A graph is said as unconnected
graph if there exist any 2 unconnected components.
Example: • H1 and H2 are connected • H3 is disconnected
Weighted Graph
•A graph is said to be weighted graph if every edge in the graph is assigned a weight or
value. It can be directed or undirected graph.
Complete Graph
•A complete graph is a graph in which there is an direct edge between every pair of vertices.
•A complete graph with n vertices will have n(n-1)/2 edges.
•There is a path from every vertex to every other vertex.
•All complete graphs are connected graphs, but not all connected graphs are complete
graphs.
•A complete digraph is a strongly connected graph.
Weakly Connected Graph:
•If there does not exist a path from one vertex to another vertex then it is
said to be a weakly connected graph.
CYCLIC AND ACYCLIC GRPH
Cyclic Graph
A graph with at least one cycle is called a cyclic
graph.
Example
In the above example graph, we have two cycles
a-b-c-d-a and c-f-g-e-c. Hence it is called a
cyclic graph
Acyclic Graph
A graph with no cycles is called an acyclic
graph.
GRAPH REPRESENTATION
Graph data structure is represented using following representations...
•Adjacency Matrix
•Incidence Matrix
•Adjacency List
ADJACENCY MATRIX
The adjacency matrix A for a graph G = (V,E) with n vertices, is an n* n
matrix of bits ,
•such that A ij = 1 , if there is an edge from vi to vj and
•Aij = 0, if there is no such edge
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
ADJACENCY LIST
•A graph containing m vertices and n edges can be represented using a
linked list, referred to as adjacency list.
•The number of vertices in a graph forms a singly linked list.
•Each vertex have a separate linked list, with nodes equal to the number of
edges connected from the corresponding vertex..
•Each nodes has at least 2 fields: VERTEX and LINK.
•The VERTEX fields contain the indices of the vertices adjacent to vertex i.
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
GRAPH TRAVERSALS
A graph traversal is a systematic way of visiting the nodes in a
specific order.
There are 2 types of graph traversals namely,
Breadth First Search(BFS)
Depth First Search(DFS)
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
DEPTH FIRST SEARCH
•Visit the first node initially, and then find the unvisited node which
is adjacent to the first node, is visited and a DFS is initiated from
the adjacent node (considering it as the first node)
•If all the adjacent nodes have been visited, backtrack to the last
node visited, and find another adjacent node and again initiate the
DFS from adjacent node
•This traversal continues until all nodes have been visited once
STEPS TO IMPLEMENT DFS
1. Select the start vertex
2. Visit the vertex ( place 1)
3. Find the adjacent vertices of visited node
Rule 1− Visit any one of the adjacent unvisited vertex. Mark it as
visited. Display it. Push it in a stack.
Rule 2− If no adjacent vertex is found, pop up a vertex from the
stack. (It will pop up all the vertices from the stack, which do not
have adjacent vertices.)
Rule 3− Repeat Rule 1 and Rule 2 until the stack is empty.
STEPS TO IMPLEMENT DFS
1. Select the start vertex
2. Visit the vertex ( place 1)
3. Find the adjacent vertices of visited node
Rule 1− Visit any one of the adjacent unvisited vertex. Mark it as
visited. Display it. Push it in a stack.
Rule 2− If no adjacent vertex is found, pop up a vertex from the
stack. (It will pop up all the vertices from the stack, which do not
have adjacent vertices.)
Rule 3− Repeat Rule 1 and Rule 2 until the stack is empty.
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
A-B-C-E-D-F-G
APPLICATIONS OF DFS
•To check whether the undirected graph is connected or not
•To check if the connected undirected graph is bi-connected or not
•To check whether the directed graph is a-cyclic or not
BFS (BREADTH FIRST SEARCH)
•Breadth First Search ( of a graph G starts from an unvisited vertex
u.
•Then all unvisited vertices vi adjacent to u are visited and then all
unvisited vertices wj adjacent to vi are visited and so on
•The traversal terminates when there are no more nodes to visit
•BFS uses a queue data structure to keep track of the order of the
nodes whose adjacent nodes are to be visited
STEPS TO IMPLEMENT BFS
1. Select the start vertex and mark it as visited (i.e) place the value 1
2. Enqueue the START vertex.
3. Dequeue the vertex.
4. Find all adjacent unvisited vertices of the dequeued vertex.
5. Mark all unvisited adjacent vertices as visited.
6. Enqueue all adjacent vertices.
7. Repeat from step 3 to step 6 until the queue becomes empty
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
A-D-B-E-C-F-G
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
APPLICATIONS OF BFS
1. To find the shortest path from a vertex s to a vertex v in an
unweighted graph
2. To find the length of such a path
3. To find out if a graph contains cycles
4. To construct a BFS tree/forest from a graph
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
TOPOLOGICAL SORTING IN GRAPHS
Graphs are data structures used to represent "connections"
between pairs of elements.
These elements are called nodes. They represent real-life objects,
persons, or entities.
The connections between nodes are called edges.
EXAMPLE APPLICATION
we could use graphs to model a transportation network where nodes
would represent facilities that send or receive products and edges
would represent roads or paths that connect them
GRAPH
A Graph is a non linear data structure consisting of nodes and
edges.
The nodes are sometimes also referred to as vertices and the
edges are lines or arcs that connect any two nodes in the graph.
Generally, a graph G is represented as G=(V,E) where V is set of
vertices and E is set of edges.
In this Graph, the set of vertices
V = {0,1,2,3,4} and the set of edges
E ={01, 12, 23, 34, 04, 14, 13}.
TOPOLOGICAL SORTING
•Topological Sorting is mainly used for scheduling jobs from the given
dependencies among jobs
•The jobs are represented by vertices, and there is an edge from x to y if job
x must be completed before job y can be started
•For example, in constructing a building, the basement must be completed
before the first floor, which must be completed before the second floor and
so on
•A topological sort gives an order in which we should perform the jobs
TOPOLOGICAL SORTING
It is a linear ordering of vertices in a directed a-cyclic graph, such that if
there is a path from Vi to Vj, then Vj appears after Vi in the linear ordering.
Topological sort is not possible if the graph has a cycle.
Procedure
1. Find the indegree for every vertex
2. Place the vertices whose indegree is zero on the empty queue
3. Dequeue one vertex at a time from the queue and decrement the
indegree of all its adjacent vertices
4. Enqueue a vertex to the queue if its indegree falls to zero
5. Repeat from step 3 unitl the queue becomes empty
The topological ordering is the order in which the vertices are dequeued.
EXAMPLE
Step 1
•Find the Indegree of vertices 1,2,3,4,5,6.
•Indegree of a vertex is the number of edges entering into the vertex.
Indegree of vertex 1 is 0, vertex 2 is 0, vertex 3 is 1, vertex 4 is 3, vertex 5
is 1, vertex 6 is 3.
Step 2
•enqueue() the vertices with Indegree 0. Therefore enqueue() vertices 1 and
2.
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
APPLICATIONS
•In computer science, applications of this type arise in instruction
scheduling, ordering of formula cell evaluation when recomputing formula
values in spreadsheets
•Determining the order of compilation tasks to perform in make files
•Data Serialization
MINIMUM SPANNING TREE
A spanning tree is a tree that connects all the vertices of a graph with the
minimum possible number of edges.
Thus, a spanning tree is always connected.
Also, a spanning tree never contains a cycle.
A Minimum Spanning Tree (MST) is a subset of edges of a connected
weighted undirected graph that connects all the vertices together with the
minimum possible total edge weight.
Spanning Tree with minimum cost is called Minimum Spanning Tree
To derive an MST, Prim’s algorithm or Kruskal’s algorithm can be used.
The initial graph
possible spanning trees
minimum spanning tree
PRIM’S ALGORITHM
•Prim’s algorithm is a greedy algorithm (Optimal solution)
•Used to form a minimum spanning tree for a connected weighted undirected
graph.
•Builds a tree that includes every vertex and a subset of the edges in such a
way that the total weight of all the edges in the tree is minimized.
ALGORITHM
//Input: A weighted connected graph G = (V, E)
//Output: T , the set of edges composing a minimum spanning tree of G
Step 1: Select a starting vertex
Step 2: Repeat Steps 3 and 4 until there is no unvisited vertices
Step 3: Select an edge e connecting the tree vertex and visit vertex that has
minimum weight
Step 4: Add the selected edge and the vertex to the minimum spanning tree
T
Step 5: EXIT
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
KRUSKAL ALGORITHM
Step-01:
Sort all the edges from low weight to high weight.
Step-02:
Take the edge with the lowest weight and use it to connect the vertices of
graph.
If adding an edge creates a cycle, then reject that edge and go for the
next least weight edge.
Step-03:
Keep adding edges until all the vertices are connected and a Minimum
Spanning Tree (MST) is obtained.
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
DIFFERENCE BETWEEN TREE AND GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
SHORTEST PATH ALGORITHM
The shortest path algorithm determines the minimum cost of the
path from source to every other vertex.
Types
The single source shortest path problem
Find the minimum cost from single source vertex to all other
vertices
Dijkstra’s Algorithm
The all pairs shortest path problem
Find the shortest distance from each vertex to all other vertices.
Floyd’s algorithm
DIJKSTRA'S ALGORITHM
Find the shortest path from a node (called the "source node") to all other
nodes in the graph, producing a shortest-path tree.
This algorithm is used in GPS devices to find the shortest path between the
current location and the destination
This algorithm was created and published by Dr. Edsger W. Dijkstra, Dutch
computer scientist and software engineer In 1959.
ALGORITHM
starts at the node that you choose (the source node) and it analyzes the graph
to find the shortest path between that node and all the other nodes in the
graph.
keeps track of the currently known shortest distance from each node to the
source node and it updates these values if it finds a shorter path.
Once the algorithm has found the shortest path between the source node and
another node, that node is marked as "visited" and added to the path.
The process continues until all the nodes in the graph have been added to the
path. This way, we have a path that connects the source node to all other nodes
following the shortest path possible to reach each node.
Dijkstra's Algorithm can only work with graphs that have positive weights
Output: 0 4 12 19 21 11 9 8 14
Explanation: The distance from 0 to 1 = 4.
The minimum distance from 0 to 2 = 12. 0->1->2
The minimum distance from 0 to 3 = 19. 0->1->2->3
The minimum distance from 0 to 4 = 21. 0->7->6->5->4
The minimum distance from 0 to 5 = 11. 0->7->6->5
The minimum distance from 0 to 6 = 9. 0->7->6
The minimum distance from 0 to 7 = 8. 0->7
The minimum distance from 0 to 8 = 14. 0->1->2->8
BI-CONNECTIVITY
An undirected graph is called Biconnected if there is a two vertex – disjoint ways
between any two vertices.
In a Biconnected Graph, there is a basic cycle through any two vertices.
It must be connected.
There isn’t an articulation point in it. ( Even if remove any node others are in
connection)
Definitions- Separation Edges and Vertices
 Let G be a connected graph
 A separation edge of G is an edge whose removal disconnects G
 A separation vertex of G is a vertex whose removal disconnects G
Applications: Separation edges and vertices represent single points of failure in a
network and are critical to the operation of the network
Example
 DFW, LGA and LAX are separation vertices
 (DFW,LAX) is a separation edge
Equivalent definitions of a biconnected graph G
 Graph G has no separation edges and no separation vertices
 For any two vertices u and v of G, there are two disjoint simple paths between u and v (i.e., two simple
paths between u and v that share no other vertices or edges)
 For any two vertices u and v of G, there is a simple cycle containing u and v
Example
Biconnected Graph
BICONNECTED COMPONENTS
Biconnected component of a graph G
 A maximal biconnected subgraph of G, or
 A subgraph consisting of a separation edge of G and its end vertices
Interaction of biconnected components
 An edge belongs to exactly one biconnected component
 A nonseparation vertex belongs to exactly one biconnected component
 A separation vertex belongs to two or more biconnected components
Example of a graph biconnected components
EULER CIRCUIT
Euler path is a path, by which we can visit every edge exactly once. (Eulerian Path)
We can use the same vertices for multiple times.
The starting and ending points need not be the same.
Euler Circuit is a special type of Euler path. (Eulerian Circuit)
When the starting vertex of the Euler path is also connected with the ending vertex of
that path, then it is called the Euler Circuit.
To detect the path and circuit, we have to follow these conditions:
 The graph must be connected.
 When exactly two vertices have odd degree, it is a Euler Path.
 Now when no vertices of an undirected graph have odd degree, then it is a Euler
Circuit.
A graph is said to be eulerian if it has a eulerian cycle.
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
APPLICATIONS OF GRAPHS
Social network graphs
 The Facebook graph showing who follows whom or who sends friend invitations to whom
Transportation networks
 vertices are intersections in road networks, and edges are the road segments that connect
them
Utility graphs:
 The power grid, the Internet, and the water network are graphs with vertices representing
connection points and edges representing the cables or pipes that connect them
Document link graphs
 web’s link graph - each web page is a vertex, and a directed edge connects each hyperlink
Finite element meshes
 spread of earthquakes through the ground, structural vibrations of a building
Robot planning
 The edges represent possible transitions between states, whereas the vertices
represent various states for the robot
Network packet traffic graph
 Vertices are IP address edges are the packets that flow between them.
Scene graph
 Computer games scene graphs represent the logical relationship between
objects in a scene
Neural networks
 Vertices represent neurons and edges the synapses between them.
Protein – Protein interactions graphs
 Vertices represent proteins and edges represent interactions between them
(biological functions in the cell)
Ad

More Related Content

Similar to UNIT IV NON LINEAR DATA STRUCTURES - GRAPH (20)

Graph data structures for ppt for understanding.pptx
Graph data structures for ppt for understanding.pptxGraph data structures for ppt for understanding.pptx
Graph data structures for ppt for understanding.pptx
ramkumar649780
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
Keno benti
 
Depth first traversal(data structure algorithms)
Depth first traversal(data structure algorithms)Depth first traversal(data structure algorithms)
Depth first traversal(data structure algorithms)
bhuvaneshwariA5
 
Graphs data structures
Graphs data structuresGraphs data structures
Graphs data structures
Jasleen Kaur (Chandigarh University)
 
data structures and algorithms Unit 2
data structures and algorithms Unit 2data structures and algorithms Unit 2
data structures and algorithms Unit 2
infanciaj
 
TREE ADT, TREE TRAVERSALS, BINARY TREE ADT
TREE ADT, TREE TRAVERSALS, BINARY TREE ADTTREE ADT, TREE TRAVERSALS, BINARY TREE ADT
TREE ADT, TREE TRAVERSALS, BINARY TREE ADT
mohanrajm63
 
LEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdfLEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdf
MuhammadUmerIhtisham
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
DhruvilSTATUS
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
Afaq Mansoor Khan
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
Victor Palmar
 
Unit VI - Graphs.ppt
Unit VI - Graphs.pptUnit VI - Graphs.ppt
Unit VI - Graphs.ppt
HODElex
 
logic.pptx
logic.pptxlogic.pptx
logic.pptx
KENNEDY GITHAIGA
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
pournima055
 
DATA STRUCTURES.pptx
DATA STRUCTURES.pptxDATA STRUCTURES.pptx
DATA STRUCTURES.pptx
KENNEDY GITHAIGA
 
ppt 1.pptx
ppt 1.pptxppt 1.pptx
ppt 1.pptx
ShasidharaniD
 
Lecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxLecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptx
king779879
 
Graphs (1)
Graphs (1)Graphs (1)
Graphs (1)
Meet Patel
 
Graph 1
Graph 1Graph 1
Graph 1
International Islamic University
 
graph representation.pdf
graph representation.pdfgraph representation.pdf
graph representation.pdf
amitbhachne
 
Graph Data Structure on social media analysis
Graph Data Structure on social media analysisGraph Data Structure on social media analysis
Graph Data Structure on social media analysis
raharjawahyuaguskade
 
Graph data structures for ppt for understanding.pptx
Graph data structures for ppt for understanding.pptxGraph data structures for ppt for understanding.pptx
Graph data structures for ppt for understanding.pptx
ramkumar649780
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
Keno benti
 
Depth first traversal(data structure algorithms)
Depth first traversal(data structure algorithms)Depth first traversal(data structure algorithms)
Depth first traversal(data structure algorithms)
bhuvaneshwariA5
 
data structures and algorithms Unit 2
data structures and algorithms Unit 2data structures and algorithms Unit 2
data structures and algorithms Unit 2
infanciaj
 
TREE ADT, TREE TRAVERSALS, BINARY TREE ADT
TREE ADT, TREE TRAVERSALS, BINARY TREE ADTTREE ADT, TREE TRAVERSALS, BINARY TREE ADT
TREE ADT, TREE TRAVERSALS, BINARY TREE ADT
mohanrajm63
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
DhruvilSTATUS
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
Victor Palmar
 
Unit VI - Graphs.ppt
Unit VI - Graphs.pptUnit VI - Graphs.ppt
Unit VI - Graphs.ppt
HODElex
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
pournima055
 
Lecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxLecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptx
king779879
 
graph representation.pdf
graph representation.pdfgraph representation.pdf
graph representation.pdf
amitbhachne
 
Graph Data Structure on social media analysis
Graph Data Structure on social media analysisGraph Data Structure on social media analysis
Graph Data Structure on social media analysis
raharjawahyuaguskade
 

More from VISWANATHAN R V (9)

UNIT II LINEAR DATA STRUCTURES – STACKS.pptx
UNIT II LINEAR DATA STRUCTURES – STACKS.pptxUNIT II LINEAR DATA STRUCTURES – STACKS.pptx
UNIT II LINEAR DATA STRUCTURES – STACKS.pptx
VISWANATHAN R V
 
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptxUNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
VISWANATHAN R V
 
UNIT III Non Linear Data Structures - Trees.pptx
UNIT III Non Linear Data Structures - Trees.pptxUNIT III Non Linear Data Structures - Trees.pptx
UNIT III Non Linear Data Structures - Trees.pptx
VISWANATHAN R V
 
UNIT I LINEAR DATA STRUCTURES – LIST .pptx
UNIT I LINEAR DATA STRUCTURES – LIST .pptxUNIT I LINEAR DATA STRUCTURES – LIST .pptx
UNIT I LINEAR DATA STRUCTURES – LIST .pptx
VISWANATHAN R V
 
CN UNIT III.pptx
CN UNIT III.pptxCN UNIT III.pptx
CN UNIT III.pptx
VISWANATHAN R V
 
CN UNIT V.pptx
CN UNIT V.pptxCN UNIT V.pptx
CN UNIT V.pptx
VISWANATHAN R V
 
CN UNIT II.pptx
CN UNIT II.pptxCN UNIT II.pptx
CN UNIT II.pptx
VISWANATHAN R V
 
CN UNIT IV ..pptx
CN UNIT IV ..pptxCN UNIT IV ..pptx
CN UNIT IV ..pptx
VISWANATHAN R V
 
CN UNIT I.pptx
CN UNIT I.pptxCN UNIT I.pptx
CN UNIT I.pptx
VISWANATHAN R V
 
UNIT II LINEAR DATA STRUCTURES – STACKS.pptx
UNIT II LINEAR DATA STRUCTURES – STACKS.pptxUNIT II LINEAR DATA STRUCTURES – STACKS.pptx
UNIT II LINEAR DATA STRUCTURES – STACKS.pptx
VISWANATHAN R V
 
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptxUNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
VISWANATHAN R V
 
UNIT III Non Linear Data Structures - Trees.pptx
UNIT III Non Linear Data Structures - Trees.pptxUNIT III Non Linear Data Structures - Trees.pptx
UNIT III Non Linear Data Structures - Trees.pptx
VISWANATHAN R V
 
UNIT I LINEAR DATA STRUCTURES – LIST .pptx
UNIT I LINEAR DATA STRUCTURES – LIST .pptxUNIT I LINEAR DATA STRUCTURES – LIST .pptx
UNIT I LINEAR DATA STRUCTURES – LIST .pptx
VISWANATHAN R V
 
Ad

Recently uploaded (20)

Building-Services-Introduction-Notes.pdf
Building-Services-Introduction-Notes.pdfBuilding-Services-Introduction-Notes.pdf
Building-Services-Introduction-Notes.pdf
Lawrence Omai
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
Redirects Unraveled: From Lost Links to Rickrolls
Redirects Unraveled: From Lost Links to RickrollsRedirects Unraveled: From Lost Links to Rickrolls
Redirects Unraveled: From Lost Links to Rickrolls
Kritika Garg
 
Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1
remoteaimms
 
A Survey of Personalized Large Language Models.pptx
A Survey of Personalized Large Language Models.pptxA Survey of Personalized Large Language Models.pptx
A Survey of Personalized Large Language Models.pptx
rutujabhaskarraopati
 
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
IJCNCJournal
 
Dynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptxDynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptx
University of Glasgow
 
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Journal of Soft Computing in Civil Engineering
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
Taqyea
 
Machine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATIONMachine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATION
DarrinBright1
 
Routing Riverdale - A New Bus Connection
Routing Riverdale - A New Bus ConnectionRouting Riverdale - A New Bus Connection
Routing Riverdale - A New Bus Connection
jzb7232
 
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning ModelsMode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Journal of Soft Computing in Civil Engineering
 
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
ijflsjournal087
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
Slide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptxSlide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptx
vvsasane
 
Surveying through global positioning system
Surveying through global positioning systemSurveying through global positioning system
Surveying through global positioning system
opneptune5
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Generative AI & Large Language Models Agents
Generative AI & Large Language Models AgentsGenerative AI & Large Language Models Agents
Generative AI & Large Language Models Agents
aasgharbee22seecs
 
Building-Services-Introduction-Notes.pdf
Building-Services-Introduction-Notes.pdfBuilding-Services-Introduction-Notes.pdf
Building-Services-Introduction-Notes.pdf
Lawrence Omai
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
Redirects Unraveled: From Lost Links to Rickrolls
Redirects Unraveled: From Lost Links to RickrollsRedirects Unraveled: From Lost Links to Rickrolls
Redirects Unraveled: From Lost Links to Rickrolls
Kritika Garg
 
Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1
remoteaimms
 
A Survey of Personalized Large Language Models.pptx
A Survey of Personalized Large Language Models.pptxA Survey of Personalized Large Language Models.pptx
A Survey of Personalized Large Language Models.pptx
rutujabhaskarraopati
 
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
IJCNCJournal
 
Dynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptxDynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptx
University of Glasgow
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
Taqyea
 
Machine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATIONMachine Learning basics POWERPOINT PRESENETATION
Machine Learning basics POWERPOINT PRESENETATION
DarrinBright1
 
Routing Riverdale - A New Bus Connection
Routing Riverdale - A New Bus ConnectionRouting Riverdale - A New Bus Connection
Routing Riverdale - A New Bus Connection
jzb7232
 
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
ijflsjournal087
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
Slide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptxSlide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptx
vvsasane
 
Surveying through global positioning system
Surveying through global positioning systemSurveying through global positioning system
Surveying through global positioning system
opneptune5
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Generative AI & Large Language Models Agents
Generative AI & Large Language Models AgentsGenerative AI & Large Language Models Agents
Generative AI & Large Language Models Agents
aasgharbee22seecs
 
Ad

UNIT IV NON LINEAR DATA STRUCTURES - GRAPH

  • 1. KONGUNADU COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF INFORMATION TECHNOLOGY 20CS301 - DATA STRUCTURES Subject Handled by Mr.R.V.Viswanathan,AP / IT KNCET.
  • 2. NON LINEAR DATA STRUCTURES - GRAPHS UNIT - IV
  • 3. Unit – IV Graphs Definitions — Topological Sort — Shortest-Path Algorithms — Dijkstra's Algorithm Minimum Spanning Tree — Prim's algorithms — Depth-First Traversal — Biconnectivity Euler circuits — Applications of graphs.
  • 4. GRAPHS Graphs are data structures used to represent "connections" between pairs of elements. These elements are called nodes. They represent real-life objects, persons, or entities. The connections between nodes are called edges.
  • 5. EXAMPLE APPLICATION example, we could use graphs to model a transportation network where nodes would represent facilities that send or receive products and edges would represent roads or paths that connect them
  • 6. WEIGHTED GRAPHS A weight graph is a graph whose edges have a "weight" or "cost". The weight of an edge can represent distance, time, or anything that models the "connection" between the pair of nodes it connects.
  • 7. INTRODUCTION TO GRAPH A Graph is a non linear data structure consisting of nodes and edges. The nodes are sometimes also referred to as vertices and the edges are lines or arcs that connect any two nodes in the graph. Generally, a graph G is represented as G=(V,E) where V is set of vertices and E is set of edges. In this Graph, the set of vertices V = {0,1,2,3,4} and the set of edges E ={01, 12, 23, 34, 04, 14, 13}.
  • 12. APPLICATIONS Graphs are used to solve many real life problems. Graphs are used to represent networks. The networks may include paths in a city or telephone network or circuit network. Graphs are also used in social networks like linkedIn , Facebook. For example, in Facebook, each person is represented with a vertex(or node). Each node is a structure and contains information like person id, name, gender, locale etc.
  • 13. TYPES OF GRAPH Directed Graph (or) Digraph •Directed graph is a graph which consists of directed edges, where each edge in E is unidirectional. •It is also referred as Digraph. If (v,w) is a directed edge then (v,w) # (w,v) Undirected Graph •An undirected graph is a graph, which consists of undirected edges. If (v,w) is an undirected edge, then (v,w)=(w,v)
  • 14. GRAPH TERMINOLOGIES •A path is a sequence of vertices such that there is an edge from each vertex to its successor •A path is simple if each vertex is distinct/A path with no repeated vertices is called a simple path •A circuit is a path in which the terminal vertex coincides with the initial vertex. (Vertices may repeat but edges are not allowed to repeat)
  • 15. GRAPH TERMINOLOGIES •Cycle: A circuit that doesn't repeat vertices is called a Cycle. (Neither vertices except possibly the starting and ending vertices) are allowed to repeat, Nor edges are allowed to repeat •Self loop: If there is an edge whose starting and end vertices are same, that is, (vi, vj) is an edge, then it is called a self loop. •Adjacent Vertices Two vertices are said to be adjacent if there is an edge (arc) connecting them. 0-1-2-3-0 - CYCLE 0-1-2-4-2-3- CIRCUIT
  • 16. GRAPH TERMINOLOGIES •Adjacent edges are edges that share a common vertex. •Degree of the Node A degree of a node is the number of edges that are connected with that node. A node with degree 0 is called as isolated node.  In degree: Number of edges entering a node  Out degree: Number of edges leaving a node  Degree = Indegree + Outdegree
  • 17. •Connected and Disconnected A graph G is said to be connected if there exists a path between every pair of vertices. A connected graph is the one in which some path exists between every two vertices (u, v) in V. There are no isolated nodes in connected graph. UNCONNECTED/DisConnected GRAPH: A graph is said as unconnected graph if there exist any 2 unconnected components. Example: • H1 and H2 are connected • H3 is disconnected
  • 18. Weighted Graph •A graph is said to be weighted graph if every edge in the graph is assigned a weight or value. It can be directed or undirected graph. Complete Graph •A complete graph is a graph in which there is an direct edge between every pair of vertices. •A complete graph with n vertices will have n(n-1)/2 edges. •There is a path from every vertex to every other vertex. •All complete graphs are connected graphs, but not all connected graphs are complete graphs. •A complete digraph is a strongly connected graph.
  • 19. Weakly Connected Graph: •If there does not exist a path from one vertex to another vertex then it is said to be a weakly connected graph.
  • 20. CYCLIC AND ACYCLIC GRPH Cyclic Graph A graph with at least one cycle is called a cyclic graph. Example In the above example graph, we have two cycles a-b-c-d-a and c-f-g-e-c. Hence it is called a cyclic graph Acyclic Graph A graph with no cycles is called an acyclic graph.
  • 21. GRAPH REPRESENTATION Graph data structure is represented using following representations... •Adjacency Matrix •Incidence Matrix •Adjacency List
  • 22. ADJACENCY MATRIX The adjacency matrix A for a graph G = (V,E) with n vertices, is an n* n matrix of bits , •such that A ij = 1 , if there is an edge from vi to vj and •Aij = 0, if there is no such edge
  • 24. ADJACENCY LIST •A graph containing m vertices and n edges can be represented using a linked list, referred to as adjacency list. •The number of vertices in a graph forms a singly linked list. •Each vertex have a separate linked list, with nodes equal to the number of edges connected from the corresponding vertex.. •Each nodes has at least 2 fields: VERTEX and LINK. •The VERTEX fields contain the indices of the vertices adjacent to vertex i.
  • 26. GRAPH TRAVERSALS A graph traversal is a systematic way of visiting the nodes in a specific order. There are 2 types of graph traversals namely, Breadth First Search(BFS) Depth First Search(DFS)
  • 28. DEPTH FIRST SEARCH •Visit the first node initially, and then find the unvisited node which is adjacent to the first node, is visited and a DFS is initiated from the adjacent node (considering it as the first node) •If all the adjacent nodes have been visited, backtrack to the last node visited, and find another adjacent node and again initiate the DFS from adjacent node •This traversal continues until all nodes have been visited once
  • 29. STEPS TO IMPLEMENT DFS 1. Select the start vertex 2. Visit the vertex ( place 1) 3. Find the adjacent vertices of visited node Rule 1− Visit any one of the adjacent unvisited vertex. Mark it as visited. Display it. Push it in a stack. Rule 2− If no adjacent vertex is found, pop up a vertex from the stack. (It will pop up all the vertices from the stack, which do not have adjacent vertices.) Rule 3− Repeat Rule 1 and Rule 2 until the stack is empty.
  • 30. STEPS TO IMPLEMENT DFS 1. Select the start vertex 2. Visit the vertex ( place 1) 3. Find the adjacent vertices of visited node Rule 1− Visit any one of the adjacent unvisited vertex. Mark it as visited. Display it. Push it in a stack. Rule 2− If no adjacent vertex is found, pop up a vertex from the stack. (It will pop up all the vertices from the stack, which do not have adjacent vertices.) Rule 3− Repeat Rule 1 and Rule 2 until the stack is empty.
  • 40. APPLICATIONS OF DFS •To check whether the undirected graph is connected or not •To check if the connected undirected graph is bi-connected or not •To check whether the directed graph is a-cyclic or not
  • 41. BFS (BREADTH FIRST SEARCH) •Breadth First Search ( of a graph G starts from an unvisited vertex u. •Then all unvisited vertices vi adjacent to u are visited and then all unvisited vertices wj adjacent to vi are visited and so on •The traversal terminates when there are no more nodes to visit •BFS uses a queue data structure to keep track of the order of the nodes whose adjacent nodes are to be visited
  • 42. STEPS TO IMPLEMENT BFS 1. Select the start vertex and mark it as visited (i.e) place the value 1 2. Enqueue the START vertex. 3. Dequeue the vertex. 4. Find all adjacent unvisited vertices of the dequeued vertex. 5. Mark all unvisited adjacent vertices as visited. 6. Enqueue all adjacent vertices. 7. Repeat from step 3 to step 6 until the queue becomes empty
  • 49. APPLICATIONS OF BFS 1. To find the shortest path from a vertex s to a vertex v in an unweighted graph 2. To find the length of such a path 3. To find out if a graph contains cycles 4. To construct a BFS tree/forest from a graph
  • 52. TOPOLOGICAL SORTING IN GRAPHS Graphs are data structures used to represent "connections" between pairs of elements. These elements are called nodes. They represent real-life objects, persons, or entities. The connections between nodes are called edges.
  • 53. EXAMPLE APPLICATION we could use graphs to model a transportation network where nodes would represent facilities that send or receive products and edges would represent roads or paths that connect them
  • 54. GRAPH A Graph is a non linear data structure consisting of nodes and edges. The nodes are sometimes also referred to as vertices and the edges are lines or arcs that connect any two nodes in the graph. Generally, a graph G is represented as G=(V,E) where V is set of vertices and E is set of edges. In this Graph, the set of vertices V = {0,1,2,3,4} and the set of edges E ={01, 12, 23, 34, 04, 14, 13}.
  • 55. TOPOLOGICAL SORTING •Topological Sorting is mainly used for scheduling jobs from the given dependencies among jobs •The jobs are represented by vertices, and there is an edge from x to y if job x must be completed before job y can be started •For example, in constructing a building, the basement must be completed before the first floor, which must be completed before the second floor and so on •A topological sort gives an order in which we should perform the jobs
  • 56. TOPOLOGICAL SORTING It is a linear ordering of vertices in a directed a-cyclic graph, such that if there is a path from Vi to Vj, then Vj appears after Vi in the linear ordering. Topological sort is not possible if the graph has a cycle. Procedure 1. Find the indegree for every vertex 2. Place the vertices whose indegree is zero on the empty queue 3. Dequeue one vertex at a time from the queue and decrement the indegree of all its adjacent vertices 4. Enqueue a vertex to the queue if its indegree falls to zero 5. Repeat from step 3 unitl the queue becomes empty The topological ordering is the order in which the vertices are dequeued.
  • 57. EXAMPLE Step 1 •Find the Indegree of vertices 1,2,3,4,5,6. •Indegree of a vertex is the number of edges entering into the vertex. Indegree of vertex 1 is 0, vertex 2 is 0, vertex 3 is 1, vertex 4 is 3, vertex 5 is 1, vertex 6 is 3. Step 2 •enqueue() the vertices with Indegree 0. Therefore enqueue() vertices 1 and 2.
  • 63. APPLICATIONS •In computer science, applications of this type arise in instruction scheduling, ordering of formula cell evaluation when recomputing formula values in spreadsheets •Determining the order of compilation tasks to perform in make files •Data Serialization
  • 64. MINIMUM SPANNING TREE A spanning tree is a tree that connects all the vertices of a graph with the minimum possible number of edges. Thus, a spanning tree is always connected. Also, a spanning tree never contains a cycle. A Minimum Spanning Tree (MST) is a subset of edges of a connected weighted undirected graph that connects all the vertices together with the minimum possible total edge weight. Spanning Tree with minimum cost is called Minimum Spanning Tree To derive an MST, Prim’s algorithm or Kruskal’s algorithm can be used.
  • 65. The initial graph possible spanning trees minimum spanning tree
  • 66. PRIM’S ALGORITHM •Prim’s algorithm is a greedy algorithm (Optimal solution) •Used to form a minimum spanning tree for a connected weighted undirected graph. •Builds a tree that includes every vertex and a subset of the edges in such a way that the total weight of all the edges in the tree is minimized.
  • 67. ALGORITHM //Input: A weighted connected graph G = (V, E) //Output: T , the set of edges composing a minimum spanning tree of G Step 1: Select a starting vertex Step 2: Repeat Steps 3 and 4 until there is no unvisited vertices Step 3: Select an edge e connecting the tree vertex and visit vertex that has minimum weight Step 4: Add the selected edge and the vertex to the minimum spanning tree T Step 5: EXIT
  • 70. KRUSKAL ALGORITHM Step-01: Sort all the edges from low weight to high weight. Step-02: Take the edge with the lowest weight and use it to connect the vertices of graph. If adding an edge creates a cycle, then reject that edge and go for the next least weight edge. Step-03: Keep adding edges until all the vertices are connected and a Minimum Spanning Tree (MST) is obtained.
  • 76. SHORTEST PATH ALGORITHM The shortest path algorithm determines the minimum cost of the path from source to every other vertex. Types The single source shortest path problem Find the minimum cost from single source vertex to all other vertices Dijkstra’s Algorithm The all pairs shortest path problem Find the shortest distance from each vertex to all other vertices. Floyd’s algorithm
  • 77. DIJKSTRA'S ALGORITHM Find the shortest path from a node (called the "source node") to all other nodes in the graph, producing a shortest-path tree. This algorithm is used in GPS devices to find the shortest path between the current location and the destination This algorithm was created and published by Dr. Edsger W. Dijkstra, Dutch computer scientist and software engineer In 1959.
  • 78. ALGORITHM starts at the node that you choose (the source node) and it analyzes the graph to find the shortest path between that node and all the other nodes in the graph. keeps track of the currently known shortest distance from each node to the source node and it updates these values if it finds a shorter path. Once the algorithm has found the shortest path between the source node and another node, that node is marked as "visited" and added to the path. The process continues until all the nodes in the graph have been added to the path. This way, we have a path that connects the source node to all other nodes following the shortest path possible to reach each node. Dijkstra's Algorithm can only work with graphs that have positive weights
  • 79. Output: 0 4 12 19 21 11 9 8 14 Explanation: The distance from 0 to 1 = 4. The minimum distance from 0 to 2 = 12. 0->1->2 The minimum distance from 0 to 3 = 19. 0->1->2->3 The minimum distance from 0 to 4 = 21. 0->7->6->5->4 The minimum distance from 0 to 5 = 11. 0->7->6->5 The minimum distance from 0 to 6 = 9. 0->7->6 The minimum distance from 0 to 7 = 8. 0->7 The minimum distance from 0 to 8 = 14. 0->1->2->8
  • 80. BI-CONNECTIVITY An undirected graph is called Biconnected if there is a two vertex – disjoint ways between any two vertices. In a Biconnected Graph, there is a basic cycle through any two vertices. It must be connected. There isn’t an articulation point in it. ( Even if remove any node others are in connection)
  • 81. Definitions- Separation Edges and Vertices  Let G be a connected graph  A separation edge of G is an edge whose removal disconnects G  A separation vertex of G is a vertex whose removal disconnects G Applications: Separation edges and vertices represent single points of failure in a network and are critical to the operation of the network Example  DFW, LGA and LAX are separation vertices  (DFW,LAX) is a separation edge
  • 82. Equivalent definitions of a biconnected graph G  Graph G has no separation edges and no separation vertices  For any two vertices u and v of G, there are two disjoint simple paths between u and v (i.e., two simple paths between u and v that share no other vertices or edges)  For any two vertices u and v of G, there is a simple cycle containing u and v Example Biconnected Graph
  • 83. BICONNECTED COMPONENTS Biconnected component of a graph G  A maximal biconnected subgraph of G, or  A subgraph consisting of a separation edge of G and its end vertices Interaction of biconnected components  An edge belongs to exactly one biconnected component  A nonseparation vertex belongs to exactly one biconnected component  A separation vertex belongs to two or more biconnected components Example of a graph biconnected components
  • 84. EULER CIRCUIT Euler path is a path, by which we can visit every edge exactly once. (Eulerian Path) We can use the same vertices for multiple times. The starting and ending points need not be the same. Euler Circuit is a special type of Euler path. (Eulerian Circuit) When the starting vertex of the Euler path is also connected with the ending vertex of that path, then it is called the Euler Circuit. To detect the path and circuit, we have to follow these conditions:  The graph must be connected.  When exactly two vertices have odd degree, it is a Euler Path.  Now when no vertices of an undirected graph have odd degree, then it is a Euler Circuit. A graph is said to be eulerian if it has a eulerian cycle.
  • 86. APPLICATIONS OF GRAPHS Social network graphs  The Facebook graph showing who follows whom or who sends friend invitations to whom Transportation networks  vertices are intersections in road networks, and edges are the road segments that connect them Utility graphs:  The power grid, the Internet, and the water network are graphs with vertices representing connection points and edges representing the cables or pipes that connect them Document link graphs  web’s link graph - each web page is a vertex, and a directed edge connects each hyperlink Finite element meshes  spread of earthquakes through the ground, structural vibrations of a building
  • 87. Robot planning  The edges represent possible transitions between states, whereas the vertices represent various states for the robot Network packet traffic graph  Vertices are IP address edges are the packets that flow between them. Scene graph  Computer games scene graphs represent the logical relationship between objects in a scene Neural networks  Vertices represent neurons and edges the synapses between them. Protein – Protein interactions graphs  Vertices represent proteins and edges represent interactions between them (biological functions in the cell)