SlideShare une entreprise Scribd logo
1  sur  82
GRAPHS
• Graph is a non-linear data structure. It
contains a set of points known as nodes (or
vertices) and a set of links known as edges (or
Arcs). Here edges are used to connect the
vertices.
• Graph is a collection of vertices and arcs in
which vertices are connected with arcs
Contd…
• Graph is a collection of nodes and edges in
which nodes are connected with edges
• Generally, a graph G is represented as G = ( V ,
E ), where V is set of vertices and E is set of
edges.
Example
• The following is a graph with 5 vertices and 6
edges.
This graph G can be defined as G = ( V , E )
Where V = {A,B,C,D,E} and E =
{(A,B),(A,C)(A,D),(B,D),(C,D),(B,E),(E,D)}.
Contd…
Graph Terminology
Vertex
Individual data element of a graph is called as
Vertex. Vertex is also known as node. In above
example graph, A, B, C, D & E are known as
vertices.
Edge
• An edge is a connecting link between two vertices. Edge is
also known as Arc. An edge is represented as
(startingVertex, endingVertex). For example, in above graph
the link between vertices A and B is represented as (A,B). In
above example graph, there are 7 edges (i.e., (A,B), (A,C),
(A,D), (B,D), (B,E), (C,D), (D,E)).
Edges are three types.
• Undirected Edge - An undirected egde is a bidirectional
edge. If there is undirected edge between vertices A and B
then edge (A , B) is equal to edge (B , A).
• Directed Edge - A directed egde is a unidirectional edge. If
there is directed edge between vertices A and B then edge
(A , B) is not equal to edge (B , A).
• Weighted Edge - A weighted egde is a edge with value
(cost) on it.
• Undirected Graph
A graph with only undirected edges is said to
be undirected graph.
• Directed Graph
A graph with only directed edges is said to be
directed graph.
• Mixed Graph
A graph with both undirected and directed
edges is said to be mixed graph.
End vertices or Endpoints
• The two vertices joined by edge are called end
vertices (or endpoints) of that edge
Origin
• If a edge is directed, its first endpoint is said to
be the origin of it.
Destination
• If a edge is directed, its first endpoint is said to
be the origin of it and the other endpoint is
said to be the destination of that edge.
Adjacent
• If there is an edge between vertices A and B
then both A and B are said to be adjacent. In
other words, vertices A and B are said to be
adjacent if there is an edge between them.
Incident
• Edge is said to be incident on a vertex if the
vertex is one of the endpoints of that edge.
Outgoing Edge
• A directed edge is said to be outgoing edge on
its origin vertex.
Incoming Edge
• A directed edge is said to be incoming edge on
its destination vertex.
Degree
• Total number of edges connected to a vertex is
said to be degree of that vertex.
Indegree
• Total number of incoming edges connected to
a vertex is said to be indegree of that vertex.
Outdegree
• Total number of outgoing edges connected to
a vertex is said to be outdegree of that vertex.
Parallel edges or Multiple edges
• If there are two undirected edges with same
end vertices and two directed edges with
same origin and destination, such edges are
called parallel edges or multiple edges.
Self-loop
• Edge (undirected or directed) is a self-loop if
its two endpoints coincide with each other.
Simple Graph
• A graph is said to be simple if there are no
parallel and self-loop edges.
Path
• A path is a sequence of alternate vertices and
edges that starts at a vertex and ends at other
vertex such that each edge is incident to its
predecessor and successor vertex.
Graph Representations
Graph data structure is represented using
following representations...
• Adjacency Matrix
• Incidence Matrix
• Adjacency List
Adjacency Matrix
• In this representation, the graph is represented using a
matrix of size total number of vertices by a total
number of vertices. That means a graph with 4 vertices
is represented using a matrix of size 4X4. In this matrix,
both rows and columns represent vertices. This matrix
is filled with either 1 or 0. Here, 1 represents that there
is an edge from row vertex to column vertex and 0
represents that there is no edge from row vertex to
column vertex.
For example, consider the following undirected graph
representation...
Contd…
Directed graph representation...
Incidence Matrix
• In this representation, the graph is represented using a
matrix of size total number of vertices by a total number of
edges. That means graph with 4 vertices and 6 edges is
represented using a matrix of size 4X6. In this matrix, rows
represent vertices and columns represents edges. This
matrix is filled with 0 or 1 or -1. Here, 0 represents that the
row edge is not connected to column vertex, 1 represents
that the row edge is connected as the outgoing edge to
column vertex and -1 represents that the row edge is
connected as the incoming edge to column vertex.
For example, consider the following directed graph
representation...
Contd…
Adjacency List
• In this representation, every vertex of a graph
contains list of its adjacent vertices.
For example, consider the following directed
graph representation implemented using
linked list...
Contd..
This representation can also be
implemented using an array as
follows..
Graph Traversal
• Graph traversal is a technique used for a searching
vertex in a graph. The graph traversal is also used to
decide the order of vertices is visited in the search
process. A graph traversal finds the edges to be used in
the search process without creating loops. That means
using graph traversal we visit all the vertices of the
graph without getting into looping path.
There are two graph traversal techniques and they are
as follows...
• DFS (Depth First Search)
• BFS (Breadth First Search)
DFS (Depth First Search)
• DFS traversal of a graph produces a spanning
tree as final result. Spanning Tree is a graph
without loops. We use Stack data
structure with maximum size of total number
of vertices in the graph to implement DFS
traversal.
We use the following steps to implement DFS
traversal...
Algorithm
• Step 1 - Define a Stack of size total number of vertices in the
graph.
• Step 2 - Select any vertex as starting point for traversal. Visit
that vertex and push it on to the Stack.
• Step 3 - Visit any one of the non-visited adjacent vertices of a
vertex which is at the top of stack and push it on to the stack.
• Step 4 - Repeat step 3 until there is no new vertex to be
visited from the vertex which is at the top of the stack.
• Step 5 - When there is no new vertex to visit then use back
tracking and pop one vertex from the stack.
• Step 6 - Repeat steps 3, 4 and 5 until stack becomes Empty.
• Step 7 - When stack becomes Empty, then produce final
spanning tree by removing unused edges from the graph
Back tracking is coming back to the
vertex from which we reached the
current vertex.
BFS (Breadth First Search)
• BFS traversal of a graph produces a spanning
tree as final result. Spanning Tree is a graph
without loops. We use Queue data
structure with maximum size of total number
of vertices in the graph to implement BFS
traversal.
Algorithm
Step 1 - Define a Queue of size total number of vertices in the
graph.
Step 2 - Select any vertex as starting point for traversal. Visit
that vertex and insert it into the Queue.
Step 3 - Visit all the non-visited adjacent vertices of the vertex
which is at front of the Queue and insert them into the
Queue.
Step 4 - When there is no new vertex to be visited from the
vertex which is at front of the Queue then delete that
vertex.
Step 5 - Repeat steps 3 and 4 until queue becomes empty.
Step 6 - When queue becomes empty, then produce final
spanning tree by removing unused edges from the graph
BFS EXAMPLE
BFS EXAMPLE
TOPOLOGICAL SORTING
• Topological Sorting is possible if and only if the
graph is a Directed Acyclic Graph.
• There may exist multiple different topological
orderings for a given directed acyclic graph.
Applications of Topological Sort-
• Scheduling jobs from the given dependencies
among jobs
• Instruction Scheduling
• Determining the order of compilation tasks to
perform in makefiles
• Data Serialization
EXAMPLE
STEPS
• Write in-degree of each vertex-
STEP 2
• Vertex-A has the least in-degree.
• So, remove vertex-A and its associated edges.
• Now, update the in-degree of other vertices.
STEP 2
STEP 3
• Vertex-A has the least in-degree.
• So, remove vertex-A and its associated edges.
• Now, update the in-degree of other vertices.
STEP 4
• There are two vertices with the least in-
degree. So, following 2 cases are possible-
• In case-01,
• Remove vertex-C and its associated edges.
• Then, update the in-degree of other vertices.
• In case-02,
• Remove vertex-D and its associated edges.
• Then, update the in-degree of other vertices.
STEP 4
STEP 5
• Now, the above two cases are continued
separately in the similar manner.
• In case-01,
• Remove vertex-D since it has the least in-degree.
• Then, remove the remaining vertex-E.
• In case-02,
• Remove vertex-C since it has the least in-degree.
• Then, remove the remaining vertex-E.
STEP 5
CONCLUSION
• For the given graph, following 2 different
topological orderings are possible-
• A B C D E
• A B D C E
https://www.cs.usfca.edu/~galles/visualization/
TopoSortIndegree.html
https://www.gatevidyalay.com/topological-sort-
topological-sorting/
Dijsktra Algorithm
• Dijkstra Algorithm is a very famous greedy
algorithm.
• It is used for solving the single source shortest
path problem.
• It computes the shortest path from one
particular source node to all other remaining
nodes of the graph.
Conditions
• It is important to note the following points regarding
Dijkstra Algorithm-
• Dijkstra algorithm works only for connected graphs.
• Dijkstra algorithm works only for those graphs that do not
contain any negative weight edge.
• The actual Dijkstra algorithm does not output the shortest
paths.
• It only provides the value or cost of the shortest paths.
• By making minor modifications in the actual algorithm, the
shortest paths can be easily obtained.
• Dijkstra algorithm works for directed as well as undirected
graphs.
Step-01
• In the first step. two sets are defined-
• One set contains all those vertices which have
been included in the shortest path tree.
• In the beginning, this set is empty.
• Other set contains all those vertices which are
still left to be included in the shortest path
tree.
• In the beginning, this set contains all the
vertices of the given graph.
Step-02:
• For each vertex of the given graph, two variables are defined as-
• Π[v] which denotes the predecessor of vertex ‘v’
• d[v] which denotes the shortest path estimate of vertex ‘v’ from the
source vertex.
• Initially, the value of these variables is set as-
• The value of variable ‘Π’ for each vertex is set to NIL i.e. Π[v] = NIL
• The value of variable ‘d’ for source vertex is set to 0 i.e. d[S] = 0
• The value of variable ‘d’ for remaining vertices is set to ∞ i.e. d[v] =
∞
Step-03:
• The following procedure is repeated until all
the vertices of the graph are processed-
• Among unprocessed vertices, a vertex with
minimum value of variable ‘d’ is chosen.
• Its outgoing edges are relaxed.
• After relaxing the edges for that vertex, the
sets created in step-01 are updated.
What is Edge Relaxation?
• Consider the edge (a,b) in the following graph-
• Here, d[a] and d[b] denotes the shortest path estimate
for vertices a and b respectively from the source vertex
‘S’.
• Now,
• If d[a] + w < d[b]
• then d[b] = d[a] + w and Π[b] = a
• This is called as edge relaxation.
EXAMPLE
STEP 1
• The following two sets are created-
• Unvisited set : {S , a , b , c , d , e}
• Visited set : { }
STEP 2
• The two variables Π and d are created for
each vertex and initialized as-
• Π[S] = Π[a] = Π[b] = Π[c] = Π[d] = Π[e] = NIL
• d[S] = 0
• d[a] = d[b] = d[c] = d[d] = d[e] = ∞
STEP 3
• Vertex ‘S’ is chosen.
• This is because shortest path estimate for
vertex ‘S’ is least.
• The outgoing edges of vertex ‘S’ are relaxed.
Before Edge Relaxation
• Now,
• d[S] + 1 = 0 + 1 = 1 < ∞
• ∴ d[a] = 1 and Π[a] = S
• d[S] + 5 = 0 + 5 = 5 < ∞
• ∴ d[b] = 5 and Π[b] = S
After Edge Relaxation
• After edge relaxation, our shortest path tree
is-
• Now, the sets are updated as-
• Unvisited set : {a , b , c , d , e}
• Visited set : {S}
Step 04
• Vertex ‘a’ is chosen.
• This is because shortest path estimate for
vertex ‘a’ is least.
• The outgoing edges of vertex ‘a’ are relaxed.
Before Edge Relaxation
• Now,
• d[a] + 2 = 1 + 2 = 3 < ∞
• ∴ d[c] = 3 and Π[c] = a
• d[a] + 1 = 1 + 1 = 2 < ∞
• ∴ d[d] = 2 and Π[d] = a
• d[b] + 2 = 1 + 2 = 3 < 5
• ∴ d[b] = 3 and Π[b] = a
EXAMPLE
After edge relaxation, our shortest
path tree is-
After edge relaxation
• Now, the sets are updated as-
• Unvisited set : {b , c , d , e}
• Visited set : {S , a}
Step-05
• Vertex ‘d’ is chosen.
• This is because shortest path estimate for
vertex ‘d’ is least.
• The outgoing edges of vertex ‘d’ are relaxed.
Before edge relaxation
• Now,
• d[d] + 2 = 2 + 2 = 4 < ∞
• ∴ d[e] = 4 and Π[e] = d
• Now, the sets are updated as-
• Unvisited set : {b , c , e}
• Visited set : {S , a , d}
After edge relaxation
Step 6
• Vertex ‘b’ is chosen.
• This is because shortest path estimate for
vertex ‘b’ is least.
• Vertex ‘c’ may also be chosen since for both
the vertices, shortest path estimate is least.
• The outgoing edges of vertex ‘b’ are relaxed.
Before Edge Relaxation
• Now,
• d[b] + 2 = 3 + 2 = 5 > 2
• ∴ No change
• After edge relaxation, our shortest path tree
remains the same as in Step-05.
• Now, the sets are updated as-
• Unvisited set : {c , e}
• Visited set : {S , a , d , b}
Step-07
• Vertex ‘c’ is chosen.
• This is because shortest path estimate for
vertex ‘c’ is least.
• The outgoing edges of vertex ‘c’ are relaxed.
Before Edge Relaxation
• Now,
• d[c] + 1 = 3 + 1 = 4 = 4
• ∴ No change
• After edge relaxation, our shortest path tree
remains the same as in Step-05.
• Now, the sets are updated as-
• Unvisited set : {e}
• Visited set : {S , a , d , b , c}
Step 8
• Vertex ‘e’ is chosen.
• This is because shortest path estimate for vertex ‘e’ is least.
• The outgoing edges of vertex ‘e’ are relaxed.
• There are no outgoing edges for vertex ‘e’.
• So, our shortest path tree remains the same as in Step-05.
• Now, the sets are updated as-
• Unvisited set : { }
• Visited set : {S , a , d , b , c , e}
Conclusion
• Now,
• All vertices of the graph are processed.
• Our final shortest path tree is as shown below.
• It represents the shortest path from source
vertex ‘S’ to all other remaining vertices.
• The order in which all the vertices are
processed is :S , a , d , b , c , e.
Final Shortest Path tree
Visualization
• https://www.cs.usfca.edu/~galles/visualizatio
n/Dijkstra.html
• https://www.gatevidyalay.com/dijkstras-
algorithm-shortest-path-algorithm/

Contenu connexe

Similaire à ppt 1.pptx

Graphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ programGraphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ programMuhammad Danish Badar
 
Graphs in datastructures
Graphs in datastructuresGraphs in datastructures
Graphs in datastructuresLikhithaGunturi
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structurePooja Bhojwani
 
Graphical reprsentation dsa (DATA STRUCTURE ALGORITHM)
Graphical reprsentation dsa (DATA STRUCTURE ALGORITHM)Graphical reprsentation dsa (DATA STRUCTURE ALGORITHM)
Graphical reprsentation dsa (DATA STRUCTURE ALGORITHM)Abdul Naqashbandi
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphsKumar
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjtepournima055
 
Lecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxLecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxking779879
 
Algorithms and data Chapter 3 V Graph.pptx
Algorithms and data Chapter 3 V Graph.pptxAlgorithms and data Chapter 3 V Graph.pptx
Algorithms and data Chapter 3 V Graph.pptxzerihunnana
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data StructureKeno benti
 
Graph Algorithms
Graph AlgorithmsGraph Algorithms
Graph AlgorithmsAshwin Shiv
 
graph representation.pdf
graph representation.pdfgraph representation.pdf
graph representation.pdfamitbhachne
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structureIkhlas Rahman
 

Similaire à ppt 1.pptx (20)

Graphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ programGraphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ program
 
Graphs
GraphsGraphs
Graphs
 
Graphs in datastructures
Graphs in datastructuresGraphs in datastructures
Graphs in datastructures
 
Graphs
GraphsGraphs
Graphs
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Unit ix graph
Unit   ix    graph Unit   ix    graph
Unit ix graph
 
Graphical reprsentation dsa (DATA STRUCTURE ALGORITHM)
Graphical reprsentation dsa (DATA STRUCTURE ALGORITHM)Graphical reprsentation dsa (DATA STRUCTURE ALGORITHM)
Graphical reprsentation dsa (DATA STRUCTURE ALGORITHM)
 
Unit 9 graph
Unit   9 graphUnit   9 graph
Unit 9 graph
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphs
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
 
Daa chpater 12
Daa chpater 12Daa chpater 12
Daa chpater 12
 
Lecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxLecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptx
 
Algorithms and data Chapter 3 V Graph.pptx
Algorithms and data Chapter 3 V Graph.pptxAlgorithms and data Chapter 3 V Graph.pptx
Algorithms and data Chapter 3 V Graph.pptx
 
Graphs
GraphsGraphs
Graphs
 
UNIT 4_DSA_KAVITHA_RMP.ppt
UNIT 4_DSA_KAVITHA_RMP.pptUNIT 4_DSA_KAVITHA_RMP.ppt
UNIT 4_DSA_KAVITHA_RMP.ppt
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
Graph Algorithms
Graph AlgorithmsGraph Algorithms
Graph Algorithms
 
graph representation.pdf
graph representation.pdfgraph representation.pdf
graph representation.pdf
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structure
 

Dernier

HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadhamedmustafa094
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxmaisarahman1
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxchumtiyababu
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...drmkjayanthikannan
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxNadaHaitham1
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 

Dernier (20)

HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 

ppt 1.pptx

  • 2. • Graph is a non-linear data structure. It contains a set of points known as nodes (or vertices) and a set of links known as edges (or Arcs). Here edges are used to connect the vertices. • Graph is a collection of vertices and arcs in which vertices are connected with arcs
  • 3. Contd… • Graph is a collection of nodes and edges in which nodes are connected with edges • Generally, a graph G is represented as G = ( V , E ), where V is set of vertices and E is set of edges.
  • 4. Example • The following is a graph with 5 vertices and 6 edges. This graph G can be defined as G = ( V , E ) Where V = {A,B,C,D,E} and E = {(A,B),(A,C)(A,D),(B,D),(C,D),(B,E),(E,D)}.
  • 6. Graph Terminology Vertex Individual data element of a graph is called as Vertex. Vertex is also known as node. In above example graph, A, B, C, D & E are known as vertices.
  • 7. Edge • An edge is a connecting link between two vertices. Edge is also known as Arc. An edge is represented as (startingVertex, endingVertex). For example, in above graph the link between vertices A and B is represented as (A,B). In above example graph, there are 7 edges (i.e., (A,B), (A,C), (A,D), (B,D), (B,E), (C,D), (D,E)). Edges are three types. • Undirected Edge - An undirected egde is a bidirectional edge. If there is undirected edge between vertices A and B then edge (A , B) is equal to edge (B , A). • Directed Edge - A directed egde is a unidirectional edge. If there is directed edge between vertices A and B then edge (A , B) is not equal to edge (B , A). • Weighted Edge - A weighted egde is a edge with value (cost) on it.
  • 8. • Undirected Graph A graph with only undirected edges is said to be undirected graph. • Directed Graph A graph with only directed edges is said to be directed graph. • Mixed Graph A graph with both undirected and directed edges is said to be mixed graph.
  • 9. End vertices or Endpoints • The two vertices joined by edge are called end vertices (or endpoints) of that edge Origin • If a edge is directed, its first endpoint is said to be the origin of it. Destination • If a edge is directed, its first endpoint is said to be the origin of it and the other endpoint is said to be the destination of that edge.
  • 10. Adjacent • If there is an edge between vertices A and B then both A and B are said to be adjacent. In other words, vertices A and B are said to be adjacent if there is an edge between them. Incident • Edge is said to be incident on a vertex if the vertex is one of the endpoints of that edge. Outgoing Edge • A directed edge is said to be outgoing edge on its origin vertex.
  • 11. Incoming Edge • A directed edge is said to be incoming edge on its destination vertex. Degree • Total number of edges connected to a vertex is said to be degree of that vertex. Indegree • Total number of incoming edges connected to a vertex is said to be indegree of that vertex.
  • 12. Outdegree • Total number of outgoing edges connected to a vertex is said to be outdegree of that vertex. Parallel edges or Multiple edges • If there are two undirected edges with same end vertices and two directed edges with same origin and destination, such edges are called parallel edges or multiple edges. Self-loop • Edge (undirected or directed) is a self-loop if its two endpoints coincide with each other.
  • 13. Simple Graph • A graph is said to be simple if there are no parallel and self-loop edges. Path • A path is a sequence of alternate vertices and edges that starts at a vertex and ends at other vertex such that each edge is incident to its predecessor and successor vertex.
  • 14. Graph Representations Graph data structure is represented using following representations... • Adjacency Matrix • Incidence Matrix • Adjacency List
  • 15. Adjacency Matrix • In this representation, the graph is represented using a matrix of size total number of vertices by a total number of vertices. That means a graph with 4 vertices is represented using a matrix of size 4X4. In this matrix, both rows and columns represent vertices. This matrix is filled with either 1 or 0. Here, 1 represents that there is an edge from row vertex to column vertex and 0 represents that there is no edge from row vertex to column vertex. For example, consider the following undirected graph representation...
  • 18. Incidence Matrix • In this representation, the graph is represented using a matrix of size total number of vertices by a total number of edges. That means graph with 4 vertices and 6 edges is represented using a matrix of size 4X6. In this matrix, rows represent vertices and columns represents edges. This matrix is filled with 0 or 1 or -1. Here, 0 represents that the row edge is not connected to column vertex, 1 represents that the row edge is connected as the outgoing edge to column vertex and -1 represents that the row edge is connected as the incoming edge to column vertex. For example, consider the following directed graph representation...
  • 20. Adjacency List • In this representation, every vertex of a graph contains list of its adjacent vertices. For example, consider the following directed graph representation implemented using linked list...
  • 22. This representation can also be implemented using an array as follows..
  • 23. Graph Traversal • Graph traversal is a technique used for a searching vertex in a graph. The graph traversal is also used to decide the order of vertices is visited in the search process. A graph traversal finds the edges to be used in the search process without creating loops. That means using graph traversal we visit all the vertices of the graph without getting into looping path. There are two graph traversal techniques and they are as follows... • DFS (Depth First Search) • BFS (Breadth First Search)
  • 24. DFS (Depth First Search) • DFS traversal of a graph produces a spanning tree as final result. Spanning Tree is a graph without loops. We use Stack data structure with maximum size of total number of vertices in the graph to implement DFS traversal. We use the following steps to implement DFS traversal...
  • 25. Algorithm • Step 1 - Define a Stack of size total number of vertices in the graph. • Step 2 - Select any vertex as starting point for traversal. Visit that vertex and push it on to the Stack. • Step 3 - Visit any one of the non-visited adjacent vertices of a vertex which is at the top of stack and push it on to the stack. • Step 4 - Repeat step 3 until there is no new vertex to be visited from the vertex which is at the top of the stack. • Step 5 - When there is no new vertex to visit then use back tracking and pop one vertex from the stack. • Step 6 - Repeat steps 3, 4 and 5 until stack becomes Empty. • Step 7 - When stack becomes Empty, then produce final spanning tree by removing unused edges from the graph
  • 26. Back tracking is coming back to the vertex from which we reached the current vertex.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35. BFS (Breadth First Search) • BFS traversal of a graph produces a spanning tree as final result. Spanning Tree is a graph without loops. We use Queue data structure with maximum size of total number of vertices in the graph to implement BFS traversal.
  • 36. Algorithm Step 1 - Define a Queue of size total number of vertices in the graph. Step 2 - Select any vertex as starting point for traversal. Visit that vertex and insert it into the Queue. Step 3 - Visit all the non-visited adjacent vertices of the vertex which is at front of the Queue and insert them into the Queue. Step 4 - When there is no new vertex to be visited from the vertex which is at front of the Queue then delete that vertex. Step 5 - Repeat steps 3 and 4 until queue becomes empty. Step 6 - When queue becomes empty, then produce final spanning tree by removing unused edges from the graph
  • 38.
  • 39.
  • 40.
  • 41.
  • 43. TOPOLOGICAL SORTING • Topological Sorting is possible if and only if the graph is a Directed Acyclic Graph. • There may exist multiple different topological orderings for a given directed acyclic graph.
  • 44. Applications of Topological Sort- • Scheduling jobs from the given dependencies among jobs • Instruction Scheduling • Determining the order of compilation tasks to perform in makefiles • Data Serialization
  • 46. STEPS • Write in-degree of each vertex-
  • 47. STEP 2 • Vertex-A has the least in-degree. • So, remove vertex-A and its associated edges. • Now, update the in-degree of other vertices.
  • 49. STEP 3 • Vertex-A has the least in-degree. • So, remove vertex-A and its associated edges. • Now, update the in-degree of other vertices.
  • 50. STEP 4 • There are two vertices with the least in- degree. So, following 2 cases are possible- • In case-01, • Remove vertex-C and its associated edges. • Then, update the in-degree of other vertices. • In case-02, • Remove vertex-D and its associated edges. • Then, update the in-degree of other vertices.
  • 52. STEP 5 • Now, the above two cases are continued separately in the similar manner. • In case-01, • Remove vertex-D since it has the least in-degree. • Then, remove the remaining vertex-E. • In case-02, • Remove vertex-C since it has the least in-degree. • Then, remove the remaining vertex-E.
  • 54. CONCLUSION • For the given graph, following 2 different topological orderings are possible- • A B C D E • A B D C E https://www.cs.usfca.edu/~galles/visualization/ TopoSortIndegree.html https://www.gatevidyalay.com/topological-sort- topological-sorting/
  • 55. Dijsktra Algorithm • Dijkstra Algorithm is a very famous greedy algorithm. • It is used for solving the single source shortest path problem. • It computes the shortest path from one particular source node to all other remaining nodes of the graph.
  • 56. Conditions • It is important to note the following points regarding Dijkstra Algorithm- • Dijkstra algorithm works only for connected graphs. • Dijkstra algorithm works only for those graphs that do not contain any negative weight edge. • The actual Dijkstra algorithm does not output the shortest paths. • It only provides the value or cost of the shortest paths. • By making minor modifications in the actual algorithm, the shortest paths can be easily obtained. • Dijkstra algorithm works for directed as well as undirected graphs.
  • 57. Step-01 • In the first step. two sets are defined- • One set contains all those vertices which have been included in the shortest path tree. • In the beginning, this set is empty. • Other set contains all those vertices which are still left to be included in the shortest path tree. • In the beginning, this set contains all the vertices of the given graph.
  • 58. Step-02: • For each vertex of the given graph, two variables are defined as- • Π[v] which denotes the predecessor of vertex ‘v’ • d[v] which denotes the shortest path estimate of vertex ‘v’ from the source vertex. • Initially, the value of these variables is set as- • The value of variable ‘Π’ for each vertex is set to NIL i.e. Π[v] = NIL • The value of variable ‘d’ for source vertex is set to 0 i.e. d[S] = 0 • The value of variable ‘d’ for remaining vertices is set to ∞ i.e. d[v] = ∞
  • 59. Step-03: • The following procedure is repeated until all the vertices of the graph are processed- • Among unprocessed vertices, a vertex with minimum value of variable ‘d’ is chosen. • Its outgoing edges are relaxed. • After relaxing the edges for that vertex, the sets created in step-01 are updated.
  • 60. What is Edge Relaxation? • Consider the edge (a,b) in the following graph- • Here, d[a] and d[b] denotes the shortest path estimate for vertices a and b respectively from the source vertex ‘S’. • Now, • If d[a] + w < d[b] • then d[b] = d[a] + w and Π[b] = a • This is called as edge relaxation.
  • 62. STEP 1 • The following two sets are created- • Unvisited set : {S , a , b , c , d , e} • Visited set : { }
  • 63. STEP 2 • The two variables Π and d are created for each vertex and initialized as- • Π[S] = Π[a] = Π[b] = Π[c] = Π[d] = Π[e] = NIL • d[S] = 0 • d[a] = d[b] = d[c] = d[d] = d[e] = ∞
  • 64. STEP 3 • Vertex ‘S’ is chosen. • This is because shortest path estimate for vertex ‘S’ is least. • The outgoing edges of vertex ‘S’ are relaxed.
  • 65. Before Edge Relaxation • Now, • d[S] + 1 = 0 + 1 = 1 < ∞ • ∴ d[a] = 1 and Π[a] = S • d[S] + 5 = 0 + 5 = 5 < ∞ • ∴ d[b] = 5 and Π[b] = S
  • 66. After Edge Relaxation • After edge relaxation, our shortest path tree is- • Now, the sets are updated as- • Unvisited set : {a , b , c , d , e} • Visited set : {S}
  • 67. Step 04 • Vertex ‘a’ is chosen. • This is because shortest path estimate for vertex ‘a’ is least. • The outgoing edges of vertex ‘a’ are relaxed.
  • 68. Before Edge Relaxation • Now, • d[a] + 2 = 1 + 2 = 3 < ∞ • ∴ d[c] = 3 and Π[c] = a • d[a] + 1 = 1 + 1 = 2 < ∞ • ∴ d[d] = 2 and Π[d] = a • d[b] + 2 = 1 + 2 = 3 < 5 • ∴ d[b] = 3 and Π[b] = a
  • 70. After edge relaxation, our shortest path tree is-
  • 71. After edge relaxation • Now, the sets are updated as- • Unvisited set : {b , c , d , e} • Visited set : {S , a}
  • 72. Step-05 • Vertex ‘d’ is chosen. • This is because shortest path estimate for vertex ‘d’ is least. • The outgoing edges of vertex ‘d’ are relaxed.
  • 73. Before edge relaxation • Now, • d[d] + 2 = 2 + 2 = 4 < ∞ • ∴ d[e] = 4 and Π[e] = d • Now, the sets are updated as- • Unvisited set : {b , c , e} • Visited set : {S , a , d}
  • 75. Step 6 • Vertex ‘b’ is chosen. • This is because shortest path estimate for vertex ‘b’ is least. • Vertex ‘c’ may also be chosen since for both the vertices, shortest path estimate is least. • The outgoing edges of vertex ‘b’ are relaxed.
  • 76. Before Edge Relaxation • Now, • d[b] + 2 = 3 + 2 = 5 > 2 • ∴ No change • After edge relaxation, our shortest path tree remains the same as in Step-05. • Now, the sets are updated as- • Unvisited set : {c , e} • Visited set : {S , a , d , b}
  • 77. Step-07 • Vertex ‘c’ is chosen. • This is because shortest path estimate for vertex ‘c’ is least. • The outgoing edges of vertex ‘c’ are relaxed.
  • 78. Before Edge Relaxation • Now, • d[c] + 1 = 3 + 1 = 4 = 4 • ∴ No change • After edge relaxation, our shortest path tree remains the same as in Step-05. • Now, the sets are updated as- • Unvisited set : {e} • Visited set : {S , a , d , b , c}
  • 79. Step 8 • Vertex ‘e’ is chosen. • This is because shortest path estimate for vertex ‘e’ is least. • The outgoing edges of vertex ‘e’ are relaxed. • There are no outgoing edges for vertex ‘e’. • So, our shortest path tree remains the same as in Step-05. • Now, the sets are updated as- • Unvisited set : { } • Visited set : {S , a , d , b , c , e}
  • 80. Conclusion • Now, • All vertices of the graph are processed. • Our final shortest path tree is as shown below. • It represents the shortest path from source vertex ‘S’ to all other remaining vertices. • The order in which all the vertices are processed is :S , a , d , b , c , e.