SlideShare a Scribd company logo
Graph
Prepared By : Ketaki Pattani
Enroll. No. : 130210107039
1
4
76
3 5
2
1 2
3
Some related terms:
• Graph: A graph G is a pair (V,E), where V is a finite
set of points called vertices and E is a finite set of
edges.
• Path: A path from a vertex v to a vertex u is a
sequence <v0,v1,v2,…,vk> of vertices where v0 ,v1,
v2… are the set of vertices followed to move from a
source to destination.
• Pathlength:The length of a path is defined as the
number of edges in the path.
Related terms: Degree of vertex
• Degree of vertex: It represents
the total number of edges linked
to a particular vertex.
• Indegree: It is the number of
incomming edges to a vertex.
•Outdegree: It is the number of
outgoing edges from a vertex.
•Source: A vertex having indegree
zero is a source.
•Sink: A vertex having outdegree
zero is a sink.
Some related terms:
• Undirected Graph: An
undirected graph is the
graph consisting of
unordered pair of vertices .
For eg :figure (a)
• Directed Graph : In a
directed graph, the edge e is
an ordered pair (u,v) which
is incident from vertex u and
is incident to vertex v. For
eg : fig(b)
Some related terms: Weighted graph
• A weighted graph is a graph
where each edge is assigned
a particular value.
• This may be the distance or
the cost.
• Here, the graph G(V,E) may
be directed or undirected
graph.
• Also the weight may be
represented by ‘W’.
Graph Representation:
Adjacency Matrix:
• Here, a two dimensional
square matrix can be used
to store a graph.
• Adjacency matrix for
undirected graph is always
symmetric .
Adjacency List
• Adjacency List creates a
seperste linked list for each
adjacent vertex.
• Adjacency graph for n nodes
is represented by an Array
of Pointers.
a
dc
b a
b
c
d
b
a
d
d c
c
a b
a c
a
dc
b
1 2
3 4
1 2 3 4
1 0 1 1 1
2 1 0 1 0
3 1 1 0 1
4 1 0 1 0
Graph Traversal:
• Most of the applications of graphs require the
traversal of graphs.
• Traversal means visiting each node in a graph
exactly once.
• It also stands for that there must be no cycles in
the traversal.
• The two commonly used techniques are:
(1) Depth First Search(DFS)
(2) Breadth First Search(BFS)
Breadth First Search:
• Strategy
 choose a starting vertex,
distance d = 0
 vertices are visited in order
of increasing distance from
the starting vertex,
 examine all edges leading
from vertices (at distance
d) to adjacent vertices (at
distance d+1)
 then, examine all edges
leading from vertices at
distance d+1 to distance
d+2, and so on,
 until no new vertex is
discovered
Algorithm for BFS:
1. for each vertex u in V[G] – {s}
2 do color[u]  white
3 d[u]  
4 [u]  nil
5 color[s]  gray
6 d[s]  0
7 [s]  nil
8 Q  
9 enqueue(Q,s)
10 while Q  
11 do u  dequeue(Q)
12 for each v in Adj[u]
13 do if color[v] = white
14 then color[v]  gray
15 d[v]  d[u] + 1
16 [v]  u
17 enqueue(Q,v)
18 color[u]  black
Example (BFS)
 0
  
 

r s t u
v w x y
Q: s
0
(Courtesy of Prof. Jim Anderson)
Example (BFS)
1 0
1  
 

r s t u
v w x y
Q: w r
1 1
Example (BFS)
1 0
1 2 
2 

r s t u
v w x y
Q: r t x
1 2 2
Example (BFS)
1 0
1 2 
2 
2
r s t u
v w x y
Q: t x v
2 2 2
Example (BFS)
1 0
1 2 
2 3
2
r s t u
v w x y
Q: x v u
2 2 3
Example (BFS)
1 0
1 2 3
2 3
2
r s t u
v w x y
Q: v u y
2 3 3
Example (BFS)
1 0
1 2 3
2 3
2
r s t u
v w x y
Q: u y
3 3
Example (BFS)
1 0
1 2 3
2 3
2
r s t u
v w x y
Q: y
3
Example (BFS)
1 0
1 2 3
2 3
2
r s t u
v w x y
Q: 
Use of a queue in BFS Graph:
• It is very common to use a queue to keep
track of:
– nodes to be visited next, or
– nodes that we have already visited.
• Typically, use of a queue leads to a breadth-
first visit order.
• Breadth-first visit order is “cautious” in the
sense that it examines every path of length i
before going on to paths of length i+1.
Depth First Search:
• Strategy
– choose a starting vertex,
distance d = 0
– examine One edges leading
from vertices (at distance d)
to adjacent vertices (at
distance d+1)
– then, examine One edges
leading from vertices at
distance d+1 to distance d+2,
and so on,
– until no new vertex is
discovered, or dead end
– then, backtrack one distance
back up, and try other edges,
and so on.
Algorithm for DFS:
.
Example (DFS)
1/
u v w
x y z
Example (DFS)
1/ 2/
u v w
x y z
Example (DFS)
1/
3/
2/
u v w
x y z
Example (DFS)
1/
4/ 3/
2/
u v w
x y z
Example (DFS)
1/
4/ 3/
2/
u v w
x y z
B
Example (DFS)
1/
4/5 3/
2/
u v w
x y z
B
Example (DFS)
1/
4/5 3/6
2/
u v w
x y z
B
Example (DFS)
1/
4/5 3/6
2/7
u v w
x y z
B
Example (DFS)
1/
4/5 3/6
2/7
u v w
x y z
BF
Example (DFS)
1/8
4/5 3/6
2/7
u v w
x y z
BF
Example (DFS)
1/8
4/5 3/6
2/7 9/
u v w
x y z
BF
Example (DFS)
1/8
4/5 3/6
2/7 9/
u v w
x y z
BF C
Example (DFS)
1/8
4/5 3/6 10/
2/7 9/
u v w
x y z
BF C
Example (DFS)
1/8
4/5 3/6 10/
2/7 9/
u v w
x y z
BF C
B
Example (DFS)
1/8
4/5 3/6 10/11
2/7 9/
u v w
x y z
BF C
B
Example (DFS)
1/8
4/5 3/6 10/11
2/7 9/12
u v w
x y z
BF C
B
Use of a stack in DFS Graph
• It is very common to use a stack to keep track
of:
– nodes to be visited next, or
– nodes that we have already visited.
• Typically, use of a stack leads to a depth-first
visit order.
• Depth-first visit order is “aggressive” in the
sense that it examines complete paths.
Minimum Spanning Tree (MST)
• it is a tree (i.e., it is acyclic)
• it covers all the vertices V
– contains |V| - 1 edges
• the total cost associated with tree edges is the
minimum among all possible spanning trees
A minimum spanning tree is a subgraph of an
undirected weighted graph G as shown, such that
Minimum Spanning Tree: Prim's
Algorithm
• Prim's algorithm for finding an MST is a greedy
algorithm.
• Start by selecting an arbitrary vertex, include
it into the current MST.
• Grow the current MST by inserting into it the
vertex closest to one of the vertices already in
current MST.
Minimum Spanning Tree: Prim's Algorithm
.
Minimum Spanning Tree: Prim's
Algorithm
.
Dijkstra's algorithm
• For a weighted graph G = (V,E,w), the single-
source shortest paths problem is to find the
shortest paths from a vertex v ∈ V to all other
vertices in V.
• Dijkstra's algorithm is similar to Prim's algorithm.
– maintains a set of nodes for which the shortest paths
are known.
– grow this set based on the node closest to source
using one of the nodes in the current shortest path
set.
Single-Source Shortest Paths: Dijkstra's
Algorithm
.
Floyd's Algorithm
• For any pair of vertices vi, vj ∈ V, consider all paths
from vi to vj whose intermediate vertices belong to
the set {v1,v2,…,vk}.
• Let pi
(
,
k
j
) (of weight di
(
,
k
j
)) be the minimum-weight
path among them.
• If vertex vk is not in the shortest path from vi to vj,
then pi
(
,
k
j
) is the same as pi
(
,
k
j
-1).
• If f vk is in pi
(
,
k
j
), then we can break pi
(
,
k
j
) into two
paths - one from vi to vk and one from vk to vj . Each
of these paths uses vertices from {v1,v2,…,vk-1}.
Floyd's Algorithm
From our observations, the following recurrence
relation follows:
This equation must be computed for each pair of nodes and
for k = 1, n. The serial complexity is O(n3).
Floyd's Algorithm
Floyd's all-pairs shortest paths algorithm.
This program computes the all-pairs shortest paths
of the graph G = (V,E) with adjacency matrix A.
130210107039 2130702

More Related Content

What's hot

Breadth first search
Breadth first searchBreadth first search
Breadth first search
Sazzad Hossain
 
Depth firstsearchalgorithm
Depth firstsearchalgorithmDepth firstsearchalgorithm
Depth firstsearchalgorithm
hansa khan
 
Graph Algorithms: Breadth-First Search (BFS)
Graph Algorithms: Breadth-First Search (BFS)Graph Algorithms: Breadth-First Search (BFS)
Graph Algorithms: Breadth-First Search (BFS)
Md. Shafiuzzaman Hira
 
Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)
Shuvongkor Barman
 
Depth-First Search
Depth-First SearchDepth-First Search
Depth-First Search
Md. Shafiuzzaman Hira
 
Breadth first search (Bfs)
Breadth first search (Bfs)Breadth first search (Bfs)
Breadth first search (Bfs)
Ishucs
 
2.5 bfs & dfs 02
2.5 bfs & dfs 022.5 bfs & dfs 02
2.5 bfs & dfs 02
Krish_ver2
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
Masud Parvaze
 
lecture 17
lecture 17lecture 17
lecture 17sajinsc
 
Graph traversal-BFS & DFS
Graph traversal-BFS & DFSGraph traversal-BFS & DFS
Graph traversal-BFS & DFS
Rajandeep Gill
 
Breadth First Search (BFS)
Breadth First Search (BFS)Breadth First Search (BFS)
Breadth First Search (BFS)
Dhrumil Panchal
 
Skiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first searchSkiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first searchzukun
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
DEEPIKA T
 
Depth First Search and Breadth First Search
Depth First Search and Breadth First SearchDepth First Search and Breadth First Search
Depth First Search and Breadth First Search
Benjamin Sach
 
2.5 graph dfs
2.5 graph dfs2.5 graph dfs
2.5 graph dfs
Krish_ver2
 
DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
satya parsana
 
lecture 18
lecture 18lecture 18
lecture 18sajinsc
 
Bfs
BfsBfs
Bfs
akila m
 
Data structures and algorithms lab7
Data structures and algorithms lab7Data structures and algorithms lab7
Data structures and algorithms lab7Bianca Teşilă
 

What's hot (20)

Bfs dfs
Bfs dfsBfs dfs
Bfs dfs
 
Breadth first search
Breadth first searchBreadth first search
Breadth first search
 
Depth firstsearchalgorithm
Depth firstsearchalgorithmDepth firstsearchalgorithm
Depth firstsearchalgorithm
 
Graph Algorithms: Breadth-First Search (BFS)
Graph Algorithms: Breadth-First Search (BFS)Graph Algorithms: Breadth-First Search (BFS)
Graph Algorithms: Breadth-First Search (BFS)
 
Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)
 
Depth-First Search
Depth-First SearchDepth-First Search
Depth-First Search
 
Breadth first search (Bfs)
Breadth first search (Bfs)Breadth first search (Bfs)
Breadth first search (Bfs)
 
2.5 bfs & dfs 02
2.5 bfs & dfs 022.5 bfs & dfs 02
2.5 bfs & dfs 02
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
lecture 17
lecture 17lecture 17
lecture 17
 
Graph traversal-BFS & DFS
Graph traversal-BFS & DFSGraph traversal-BFS & DFS
Graph traversal-BFS & DFS
 
Breadth First Search (BFS)
Breadth First Search (BFS)Breadth First Search (BFS)
Breadth First Search (BFS)
 
Skiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first searchSkiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first search
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
 
Depth First Search and Breadth First Search
Depth First Search and Breadth First SearchDepth First Search and Breadth First Search
Depth First Search and Breadth First Search
 
2.5 graph dfs
2.5 graph dfs2.5 graph dfs
2.5 graph dfs
 
DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
 
lecture 18
lecture 18lecture 18
lecture 18
 
Bfs
BfsBfs
Bfs
 
Data structures and algorithms lab7
Data structures and algorithms lab7Data structures and algorithms lab7
Data structures and algorithms lab7
 

Viewers also liked

Application of dfs
Application of dfsApplication of dfs
Application of dfs
Hossain Md Shakhawat
 
Search algorithms master
Search algorithms masterSearch algorithms master
Search algorithms master
Hossam Hassan
 
Linear and Binary Search Algorithms.(Discrete Mathematics)
Linear and Binary Search Algorithms.(Discrete Mathematics)Linear and Binary Search Algorithms.(Discrete Mathematics)
Linear and Binary Search Algorithms.(Discrete Mathematics)
Shanawaz Ahamed
 
Ch2 3-informed (heuristic) search
Ch2 3-informed (heuristic) searchCh2 3-informed (heuristic) search
Ch2 3-informed (heuristic) searchchandsek666
 
Heuristic Search
Heuristic SearchHeuristic Search
Heuristic Searchbutest
 
ADA complete notes
ADA complete notesADA complete notes
ADA complete notes
Vinay Kumar C
 
Algorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class NotesAlgorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class Notes
Kumar Avinash
 
Hillclimbing search algorthim #introduction
Hillclimbing search algorthim #introductionHillclimbing search algorthim #introduction
Hillclimbing search algorthim #introduction
Mohamed Gad
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
Arvind Krishnaa
 
Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}
FellowBuddy.com
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
Intro C# Book
 

Viewers also liked (12)

Application of dfs
Application of dfsApplication of dfs
Application of dfs
 
Search algorithms master
Search algorithms masterSearch algorithms master
Search algorithms master
 
Linear and Binary Search Algorithms.(Discrete Mathematics)
Linear and Binary Search Algorithms.(Discrete Mathematics)Linear and Binary Search Algorithms.(Discrete Mathematics)
Linear and Binary Search Algorithms.(Discrete Mathematics)
 
Ch2 3-informed (heuristic) search
Ch2 3-informed (heuristic) searchCh2 3-informed (heuristic) search
Ch2 3-informed (heuristic) search
 
Heuristic Search
Heuristic SearchHeuristic Search
Heuristic Search
 
ADA complete notes
ADA complete notesADA complete notes
ADA complete notes
 
Algorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class NotesAlgorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class Notes
 
Hillclimbing search algorthim #introduction
Hillclimbing search algorthim #introductionHillclimbing search algorthim #introduction
Hillclimbing search algorthim #introduction
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Hill climbing
Hill climbingHill climbing
Hill climbing
 
Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
 

Similar to 130210107039 2130702

Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
Pooja Bhojwani
 
Graph
GraphGraph
Graphs in data structures
Graphs in data structuresGraphs in data structures
Graphs in data structures
Savit Chandra
 
DIJKSTRA_123.pptx
DIJKSTRA_123.pptxDIJKSTRA_123.pptx
DIJKSTRA_123.pptx
KrishnaSawant8
 
Unit 9 graph
Unit   9 graphUnit   9 graph
Unit 9 graph
Dabbal Singh Mahara
 
Unit ix graph
Unit   ix    graph Unit   ix    graph
Unit ix graph
Tribhuvan University
 
19-graph1 (1).ppt
19-graph1 (1).ppt19-graph1 (1).ppt
19-graph1 (1).ppt
Himajanaidu2
 
Chap10 slides
Chap10 slidesChap10 slides
Chap10 slides
HJ DS
 
Graphs
GraphsGraphs
LEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdfLEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdf
MuhammadUmerIhtisham
 
Shortest path
Shortest pathShortest path
Shortest path
Ruchika Sinha
 
B.tech admission in india
B.tech admission in indiaB.tech admission in india
B.tech admission in india
Edhole.com
 
22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp
22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp
22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp
chandrashekarr799
 
9_graphs2.v4.ppt
9_graphs2.v4.ppt9_graphs2.v4.ppt
9_graphs2.v4.ppt
tariqghufran458
 
22-graphs1-dfs-bfs.ppt
22-graphs1-dfs-bfs.ppt22-graphs1-dfs-bfs.ppt
22-graphs1-dfs-bfs.ppt
KarunaBiswas3
 
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdfClass01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
ChristianKapsales1
 
Graph 3
Graph 3Graph 3
graph.pptx
graph.pptxgraph.pptx
graph.pptx
hijigaf
 

Similar to 130210107039 2130702 (20)

Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Graph
GraphGraph
Graph
 
Graphs in data structures
Graphs in data structuresGraphs in data structures
Graphs in data structures
 
DIJKSTRA_123.pptx
DIJKSTRA_123.pptxDIJKSTRA_123.pptx
DIJKSTRA_123.pptx
 
Unit 9 graph
Unit   9 graphUnit   9 graph
Unit 9 graph
 
Unit ix graph
Unit   ix    graph Unit   ix    graph
Unit ix graph
 
19-graph1 (1).ppt
19-graph1 (1).ppt19-graph1 (1).ppt
19-graph1 (1).ppt
 
Chap10 slides
Chap10 slidesChap10 slides
Chap10 slides
 
Graphs
GraphsGraphs
Graphs
 
Graphs
GraphsGraphs
Graphs
 
LEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdfLEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdf
 
Shortest path
Shortest pathShortest path
Shortest path
 
B.tech admission in india
B.tech admission in indiaB.tech admission in india
B.tech admission in india
 
22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp
22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp
22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp
 
9_graphs2.v4.ppt
9_graphs2.v4.ppt9_graphs2.v4.ppt
9_graphs2.v4.ppt
 
22-graphs1-dfs-bfs.ppt
22-graphs1-dfs-bfs.ppt22-graphs1-dfs-bfs.ppt
22-graphs1-dfs-bfs.ppt
 
Graps 2
Graps 2Graps 2
Graps 2
 
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdfClass01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
 
Graph 3
Graph 3Graph 3
Graph 3
 
graph.pptx
graph.pptxgraph.pptx
graph.pptx
 

Recently uploaded

Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 

Recently uploaded (20)

Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 

130210107039 2130702

  • 1. Graph Prepared By : Ketaki Pattani Enroll. No. : 130210107039 1 4 76 3 5 2 1 2 3
  • 2. Some related terms: • Graph: A graph G is a pair (V,E), where V is a finite set of points called vertices and E is a finite set of edges. • Path: A path from a vertex v to a vertex u is a sequence <v0,v1,v2,…,vk> of vertices where v0 ,v1, v2… are the set of vertices followed to move from a source to destination. • Pathlength:The length of a path is defined as the number of edges in the path.
  • 3. Related terms: Degree of vertex • Degree of vertex: It represents the total number of edges linked to a particular vertex. • Indegree: It is the number of incomming edges to a vertex. •Outdegree: It is the number of outgoing edges from a vertex. •Source: A vertex having indegree zero is a source. •Sink: A vertex having outdegree zero is a sink.
  • 4. Some related terms: • Undirected Graph: An undirected graph is the graph consisting of unordered pair of vertices . For eg :figure (a) • Directed Graph : In a directed graph, the edge e is an ordered pair (u,v) which is incident from vertex u and is incident to vertex v. For eg : fig(b)
  • 5. Some related terms: Weighted graph • A weighted graph is a graph where each edge is assigned a particular value. • This may be the distance or the cost. • Here, the graph G(V,E) may be directed or undirected graph. • Also the weight may be represented by ‘W’.
  • 6. Graph Representation: Adjacency Matrix: • Here, a two dimensional square matrix can be used to store a graph. • Adjacency matrix for undirected graph is always symmetric . Adjacency List • Adjacency List creates a seperste linked list for each adjacent vertex. • Adjacency graph for n nodes is represented by an Array of Pointers. a dc b a b c d b a d d c c a b a c a dc b 1 2 3 4 1 2 3 4 1 0 1 1 1 2 1 0 1 0 3 1 1 0 1 4 1 0 1 0
  • 7. Graph Traversal: • Most of the applications of graphs require the traversal of graphs. • Traversal means visiting each node in a graph exactly once. • It also stands for that there must be no cycles in the traversal. • The two commonly used techniques are: (1) Depth First Search(DFS) (2) Breadth First Search(BFS)
  • 8. Breadth First Search: • Strategy  choose a starting vertex, distance d = 0  vertices are visited in order of increasing distance from the starting vertex,  examine all edges leading from vertices (at distance d) to adjacent vertices (at distance d+1)  then, examine all edges leading from vertices at distance d+1 to distance d+2, and so on,  until no new vertex is discovered
  • 9. Algorithm for BFS: 1. for each vertex u in V[G] – {s} 2 do color[u]  white 3 d[u]   4 [u]  nil 5 color[s]  gray 6 d[s]  0 7 [s]  nil 8 Q   9 enqueue(Q,s) 10 while Q   11 do u  dequeue(Q) 12 for each v in Adj[u] 13 do if color[v] = white 14 then color[v]  gray 15 d[v]  d[u] + 1 16 [v]  u 17 enqueue(Q,v) 18 color[u]  black
  • 10. Example (BFS)  0       r s t u v w x y Q: s 0 (Courtesy of Prof. Jim Anderson)
  • 11. Example (BFS) 1 0 1      r s t u v w x y Q: w r 1 1
  • 12. Example (BFS) 1 0 1 2  2   r s t u v w x y Q: r t x 1 2 2
  • 13. Example (BFS) 1 0 1 2  2  2 r s t u v w x y Q: t x v 2 2 2
  • 14. Example (BFS) 1 0 1 2  2 3 2 r s t u v w x y Q: x v u 2 2 3
  • 15. Example (BFS) 1 0 1 2 3 2 3 2 r s t u v w x y Q: v u y 2 3 3
  • 16. Example (BFS) 1 0 1 2 3 2 3 2 r s t u v w x y Q: u y 3 3
  • 17. Example (BFS) 1 0 1 2 3 2 3 2 r s t u v w x y Q: y 3
  • 18. Example (BFS) 1 0 1 2 3 2 3 2 r s t u v w x y Q: 
  • 19. Use of a queue in BFS Graph: • It is very common to use a queue to keep track of: – nodes to be visited next, or – nodes that we have already visited. • Typically, use of a queue leads to a breadth- first visit order. • Breadth-first visit order is “cautious” in the sense that it examines every path of length i before going on to paths of length i+1.
  • 20. Depth First Search: • Strategy – choose a starting vertex, distance d = 0 – examine One edges leading from vertices (at distance d) to adjacent vertices (at distance d+1) – then, examine One edges leading from vertices at distance d+1 to distance d+2, and so on, – until no new vertex is discovered, or dead end – then, backtrack one distance back up, and try other edges, and so on.
  • 32. Example (DFS) 1/8 4/5 3/6 2/7 9/ u v w x y z BF
  • 33. Example (DFS) 1/8 4/5 3/6 2/7 9/ u v w x y z BF C
  • 34. Example (DFS) 1/8 4/5 3/6 10/ 2/7 9/ u v w x y z BF C
  • 35. Example (DFS) 1/8 4/5 3/6 10/ 2/7 9/ u v w x y z BF C B
  • 36. Example (DFS) 1/8 4/5 3/6 10/11 2/7 9/ u v w x y z BF C B
  • 37. Example (DFS) 1/8 4/5 3/6 10/11 2/7 9/12 u v w x y z BF C B
  • 38. Use of a stack in DFS Graph • It is very common to use a stack to keep track of: – nodes to be visited next, or – nodes that we have already visited. • Typically, use of a stack leads to a depth-first visit order. • Depth-first visit order is “aggressive” in the sense that it examines complete paths.
  • 39. Minimum Spanning Tree (MST) • it is a tree (i.e., it is acyclic) • it covers all the vertices V – contains |V| - 1 edges • the total cost associated with tree edges is the minimum among all possible spanning trees A minimum spanning tree is a subgraph of an undirected weighted graph G as shown, such that
  • 40. Minimum Spanning Tree: Prim's Algorithm • Prim's algorithm for finding an MST is a greedy algorithm. • Start by selecting an arbitrary vertex, include it into the current MST. • Grow the current MST by inserting into it the vertex closest to one of the vertices already in current MST.
  • 41. Minimum Spanning Tree: Prim's Algorithm .
  • 42. Minimum Spanning Tree: Prim's Algorithm .
  • 43. Dijkstra's algorithm • For a weighted graph G = (V,E,w), the single- source shortest paths problem is to find the shortest paths from a vertex v ∈ V to all other vertices in V. • Dijkstra's algorithm is similar to Prim's algorithm. – maintains a set of nodes for which the shortest paths are known. – grow this set based on the node closest to source using one of the nodes in the current shortest path set.
  • 44. Single-Source Shortest Paths: Dijkstra's Algorithm .
  • 45. Floyd's Algorithm • For any pair of vertices vi, vj ∈ V, consider all paths from vi to vj whose intermediate vertices belong to the set {v1,v2,…,vk}. • Let pi ( , k j ) (of weight di ( , k j )) be the minimum-weight path among them. • If vertex vk is not in the shortest path from vi to vj, then pi ( , k j ) is the same as pi ( , k j -1). • If f vk is in pi ( , k j ), then we can break pi ( , k j ) into two paths - one from vi to vk and one from vk to vj . Each of these paths uses vertices from {v1,v2,…,vk-1}.
  • 46. Floyd's Algorithm From our observations, the following recurrence relation follows: This equation must be computed for each pair of nodes and for k = 1, n. The serial complexity is O(n3).
  • 47. Floyd's Algorithm Floyd's all-pairs shortest paths algorithm. This program computes the all-pairs shortest paths of the graph G = (V,E) with adjacency matrix A.