SlideShare a Scribd company logo
Graph
What is a Graph?
 A data Structure that consists of a set of
nodes(vertices) and a set of edges that relate the node
to each other.
 The set of edges describes relationship among the
vertices.
edge
Node
Formal Definition Of Graphs
 A graph G is defined as follows:
G=(V,E)
V: set of vertices
E:set of edges connecting the vertices in V
An edge e=(u , v) is a pair of vertices
Example:
a b
c d
e
V={a,bc,d,e}
E={(a,b),(a,c),(a,d),(b,e)
,(c,d),(c,e),(d,e)}
 When the edges in a graph have no direction , the
graph is called undirected.
 When the edges in a graph have a direction , the graph
is called directed.
Undirected edge Directed edge
a b a b
1
2
5
4
3
1
2
5
4
3
Undirected Graph Directed Graph
 Adjacent nodes : two nodes are adjacent if they are
connected by an edge.
 Path : a sequence of vertices that connect two nodes
in a graph
 Simple path : A simple path is a path in which all
vertices , except possibly in the first and last ,are
different.
 Complete Graph: a graph in which every vertex is
directly connected to every other vertex
a b
A is adjacent to b
 Adjacency matrix representation.
 Adjacency lists representation.
Adjacency matrix
Let G=(V , E) be a graph with n vertices.
The adjacency matrix of G is a two dimensional array n by
n , say A[5][5].
A B
C D
E
(A) 1
(B) 2
(C) 3
(D)4
(E)5
(A)1 (B)2 (C)3 (D)4 (E)5
0 1 1 1 0
01 0 1 0
1 0 0 1 1
1 1 1 0 1
0 0 1 1 0
When the adjacent vertices of a graph is represented in the form of matrix
then such type of representation is called Adjacency Matrix
Representation of graph. E.g. A[i][j]
Number of rows = Number of Column
A ij =
O , if Vi is not adjacent to Vj
1 , if Vi , Vj is adjacent
Adjacency lists
B C
E
A D
NODE ADJACENCY LIST
A B , C , D
B C
C NULL
D C , E
E C
When the vertices of graph are represented by the linked
list then such type of representation is called adjacency list
representation of graph.
Traverse all node in the graph.
Methods
* Breadth – First Search
*Depth - First Search
Breadth First Search(BFS)
*BFS uses queue.
Logic
*During execution of algorithms , each node N of G will be
in one of three states called status of N:
- STATUS = 1(Ready state)
- STATUS = 2(Waiting state)
- STATUS= 3(Processed state)
ED
C
F
A
B
Algorithm
1.Initialize all nodes to the ready state
(STATUS=1)
2.Put the starting node A in Queue and
change its status to the waiting state
(STATUS=2)
3. [LOOP]
Repeat steps 4 and 5 until queue is empty
4. Remove the front node N of Queue.
Process N and change the status of N to
the processed state (STATUS=3)
5. Add to the rear of queue all the
neighbors of N that are in ready state
(STATUS=1), and change their status to
waiting state (STATUS=2).
[End of Loop]
6. Exit
A
ED
CB
F
1.Initialize all nodes to the ready state
(STATUS=1)
1
1
1
1
1
1
2.Put the starting node A in Queue and
change its status to the waiting state
(STATUS=2)
A
2 1.Initialize all nodes to the ready state
(STATUS=1)
2.Put the starting node A in Queue and
change its status to the waiting state
(STATUS=2)
3. [LOOP]
Repeat steps 4 and 5 until queue is
empty
4. Remove the front node N of Queue.
Process N and change the status of N
to the processed state (STATUS=3)
5. Add to the rear of queue all the
neighbors of N that are in ready state
(STATUS=1), and change their status to
waiting state (STATUS=2).
[End of Loop]
6. Exit
3
B C E
2 2
2
D F
3
2
2
3
3
3
3
B
A
C E
D F
Traversing order – A B C E D F
Depth First Search (DFS)
* DFS uses stack
*During execution of algorithms , each node N of G will be
in one of three states called status of N:
- STATUS = 1(Ready state)
- STATUS = 2(Waiting state)
- STATUS= 3(Processed state)
Logic
A F
D
C E
B
1.Initialize all nodes to the ready state
(STATUS=1)
2.Push the starting node A onto stack
and change its status to the waiting state
(STATUS=2)
3. [LOOP]
Repeat steps 4 and 5 until stack is
empty
4. Pop the top node N of Stack.
Process N and change the status of N
to the processed state (STATUS=3)
5. Push onto Stack all the neighbors of
N that are still in ready state
(STATUS=1), and change their status to
waiting state (STATUS=2).
[End of Loop]
6. Exit
Algorithm
A F
D
C E
B
1.Initialize all nodes to the ready state
(STATUS=1)
1
1
11
1
1
2.Push the starting node A onto stack
and change its status to the waiting state
(STATUS=2)
A
2
A
1.Initialize all nodes to the ready state
(STATUS=1)
2.Push the starting node A onto stack
and change its status to the waiting state
(STATUS=2)
3. [LOOP]
Repeat steps 4 and 5 until stack is
empty
4. Pop the top node N of Stack.
Process N and change the status of N
to the processed state (STATUS=3)
5. Push onto Stack all the neighbors of
N that are still in ready state
(STATUS=1), and change their status to
waiting state (STATUS=2).
[End of Loop]
6. Exit
A
B
C
3
2
2
C
3
D
E
2
2
E
3
F
2
F
3
3 3
D B
Traversing order is
A C E F D B
A
C
E
F
D
B
Thank you
Jagjot singh chopra
Shivam khanna
2016 csa 1569 2016csa1556

More Related Content

What's hot

Graphs in c language
Graphs in c languageGraphs in c language
Graphs in c language
SARITHA REDDY
 
Graph representation
Graph representationGraph representation
Graph representation
Tech_MX
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
Pooja Bhojwani
 
Graph
GraphGraph
Skiena algorithm 2007 lecture10 graph data strctures
Skiena algorithm 2007 lecture10 graph data strcturesSkiena algorithm 2007 lecture10 graph data strctures
Skiena algorithm 2007 lecture10 graph data strctures
zukun
 
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structure
hamza javed
 
Graph (Data structure)
Graph (Data structure) Graph (Data structure)
Graph (Data structure)
shamiur rahman
 
Graphss
GraphssGraphss
Graphss
fika sweety
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
Madhu Bala
 
Graphs in Data Structure
 Graphs in Data Structure Graphs in Data Structure
Graphs in Data Structure
hafsa komal
 
Lecture8 data structure(graph)
Lecture8 data structure(graph)Lecture8 data structure(graph)
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
Anuj Modi
 
Graph
GraphGraph
Graph
sakthisree
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
Afaq Mansoor Khan
 
Graphs
GraphsGraphs
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
Keno benti
 
Graph theory
Graph theoryGraph theory
Graph theory
Jeane Paguio
 
Graphs in Data Structure
Graphs in Data StructureGraphs in Data Structure
Graphs in Data Structure
lalithambiga kamaraj
 
Graph data structure
Graph data structureGraph data structure
Graph data structure
Tech_MX
 
Graph Theory: Matrix representation of graphs
Graph Theory: Matrix representation of graphsGraph Theory: Matrix representation of graphs
Graph Theory: Matrix representation of graphs
Ashikur Rahman
 

What's hot (20)

Graphs in c language
Graphs in c languageGraphs in c language
Graphs in c language
 
Graph representation
Graph representationGraph representation
Graph representation
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Graph
GraphGraph
Graph
 
Skiena algorithm 2007 lecture10 graph data strctures
Skiena algorithm 2007 lecture10 graph data strcturesSkiena algorithm 2007 lecture10 graph data strctures
Skiena algorithm 2007 lecture10 graph data strctures
 
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structure
 
Graph (Data structure)
Graph (Data structure) Graph (Data structure)
Graph (Data structure)
 
Graphss
GraphssGraphss
Graphss
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
 
Graphs in Data Structure
 Graphs in Data Structure Graphs in Data Structure
Graphs in Data Structure
 
Lecture8 data structure(graph)
Lecture8 data structure(graph)Lecture8 data structure(graph)
Lecture8 data structure(graph)
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
 
Graph
GraphGraph
Graph
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
Graphs
GraphsGraphs
Graphs
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
Graph theory
Graph theoryGraph theory
Graph theory
 
Graphs in Data Structure
Graphs in Data StructureGraphs in Data Structure
Graphs in Data Structure
 
Graph data structure
Graph data structureGraph data structure
Graph data structure
 
Graph Theory: Matrix representation of graphs
Graph Theory: Matrix representation of graphsGraph Theory: Matrix representation of graphs
Graph Theory: Matrix representation of graphs
 

Similar to Data structure

Chap 8 graph
Chap 8 graphChap 8 graph
Chap 8 graph
Raj Sarode
 
Graphs
GraphsGraphs
Graphs
amudha arul
 
Graphs
GraphsGraphs
6. Graphs
6. Graphs6. Graphs
6. Graphs
Mandeep Singh
 
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
zerihunnana
 
Data Structures and Agorithm: DS 21 Graph Theory.pptx
Data Structures and Agorithm: DS 21 Graph Theory.pptxData Structures and Agorithm: DS 21 Graph Theory.pptx
Data Structures and Agorithm: DS 21 Graph Theory.pptx
RashidFaridChishti
 
GRAPH - DISCRETE STRUCTURE AND ALGORITHM
GRAPH - DISCRETE STRUCTURE AND ALGORITHMGRAPH - DISCRETE STRUCTURE AND ALGORITHM
GRAPH - DISCRETE STRUCTURE AND ALGORITHM
himanshumishra19dec
 
Graphs
GraphsGraphs
Topological sort
Topological sortTopological sort
Topological sort
jabishah
 
Matrix representation of graph
Matrix representation of graphMatrix representation of graph
Matrix representation of graph
Rounak Biswas
 
graph theory
graph theorygraph theory
graph theory
Shashank Singh
 
Data Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph TraversalData Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph Traversal
ManishPrajapati78
 
Graps 2
Graps 2Graps 2
Chap 6 Graph.ppt
Chap 6 Graph.pptChap 6 Graph.ppt
Chap 6 Graph.ppt
shashankbhadouria4
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
 
Graph
GraphGraph
topologicalsort-using c++ as development language.pptx
topologicalsort-using c++ as development language.pptxtopologicalsort-using c++ as development language.pptx
topologicalsort-using c++ as development language.pptx
janafridi251
 
Lecture 03 lexical analysis
Lecture 03 lexical analysisLecture 03 lexical analysis
Lecture 03 lexical analysis
Iffat Anjum
 
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
 

Similar to Data structure (20)

Chap 8 graph
Chap 8 graphChap 8 graph
Chap 8 graph
 
Graphs
GraphsGraphs
Graphs
 
Graphs
GraphsGraphs
Graphs
 
6. Graphs
6. Graphs6. Graphs
6. Graphs
 
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
 
Data Structures and Agorithm: DS 21 Graph Theory.pptx
Data Structures and Agorithm: DS 21 Graph Theory.pptxData Structures and Agorithm: DS 21 Graph Theory.pptx
Data Structures and Agorithm: DS 21 Graph Theory.pptx
 
GRAPH - DISCRETE STRUCTURE AND ALGORITHM
GRAPH - DISCRETE STRUCTURE AND ALGORITHMGRAPH - DISCRETE STRUCTURE AND ALGORITHM
GRAPH - DISCRETE STRUCTURE AND ALGORITHM
 
Graphs
GraphsGraphs
Graphs
 
Topological sort
Topological sortTopological sort
Topological sort
 
Matrix representation of graph
Matrix representation of graphMatrix representation of graph
Matrix representation of graph
 
graph theory
graph theorygraph theory
graph theory
 
Data Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph TraversalData Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph Traversal
 
Graps 2
Graps 2Graps 2
Graps 2
 
Chap 6 Graph.ppt
Chap 6 Graph.pptChap 6 Graph.ppt
Chap 6 Graph.ppt
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Graph
GraphGraph
Graph
 
topologicalsort-using c++ as development language.pptx
topologicalsort-using c++ as development language.pptxtopologicalsort-using c++ as development language.pptx
topologicalsort-using c++ as development language.pptx
 
Lecture 03 lexical analysis
Lecture 03 lexical analysisLecture 03 lexical analysis
Lecture 03 lexical analysis
 
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
 

Recently uploaded

Intelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicineIntelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicine
AndrzejJarynowski
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
Sm321
 
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
bopyb
 
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
74nqk8xf
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
slg6lamcq
 
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
zsjl4mimo
 
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
u86oixdj
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
u86oixdj
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
Lars Albertsson
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
apvysm8
 
State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023
kuntobimo2016
 
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdfEnhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
GetInData
 
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
v7oacc3l
 
Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
jerlynmaetalle
 
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
v3tuleee
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
manishkhaire30
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
javier ramirez
 
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
ahzuo
 
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging DataPredictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Kiwi Creative
 
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
mzpolocfi
 

Recently uploaded (20)

Intelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicineIntelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicine
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
 
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
 
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
 
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
 
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
 
State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023
 
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdfEnhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
 
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
 
Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
 
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
 
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
 
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging DataPredictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
 
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
 

Data structure

  • 2. What is a Graph?  A data Structure that consists of a set of nodes(vertices) and a set of edges that relate the node to each other.  The set of edges describes relationship among the vertices. edge Node
  • 3. Formal Definition Of Graphs  A graph G is defined as follows: G=(V,E) V: set of vertices E:set of edges connecting the vertices in V An edge e=(u , v) is a pair of vertices Example: a b c d e V={a,bc,d,e} E={(a,b),(a,c),(a,d),(b,e) ,(c,d),(c,e),(d,e)}
  • 4.  When the edges in a graph have no direction , the graph is called undirected.  When the edges in a graph have a direction , the graph is called directed. Undirected edge Directed edge a b a b 1 2 5 4 3 1 2 5 4 3 Undirected Graph Directed Graph
  • 5.  Adjacent nodes : two nodes are adjacent if they are connected by an edge.  Path : a sequence of vertices that connect two nodes in a graph  Simple path : A simple path is a path in which all vertices , except possibly in the first and last ,are different.  Complete Graph: a graph in which every vertex is directly connected to every other vertex a b A is adjacent to b
  • 6.  Adjacency matrix representation.  Adjacency lists representation.
  • 7. Adjacency matrix Let G=(V , E) be a graph with n vertices. The adjacency matrix of G is a two dimensional array n by n , say A[5][5]. A B C D E (A) 1 (B) 2 (C) 3 (D)4 (E)5 (A)1 (B)2 (C)3 (D)4 (E)5 0 1 1 1 0 01 0 1 0 1 0 0 1 1 1 1 1 0 1 0 0 1 1 0 When the adjacent vertices of a graph is represented in the form of matrix then such type of representation is called Adjacency Matrix Representation of graph. E.g. A[i][j] Number of rows = Number of Column A ij = O , if Vi is not adjacent to Vj 1 , if Vi , Vj is adjacent
  • 8. Adjacency lists B C E A D NODE ADJACENCY LIST A B , C , D B C C NULL D C , E E C When the vertices of graph are represented by the linked list then such type of representation is called adjacency list representation of graph.
  • 9. Traverse all node in the graph. Methods * Breadth – First Search *Depth - First Search
  • 10. Breadth First Search(BFS) *BFS uses queue. Logic *During execution of algorithms , each node N of G will be in one of three states called status of N: - STATUS = 1(Ready state) - STATUS = 2(Waiting state) - STATUS= 3(Processed state)
  • 11. ED C F A B Algorithm 1.Initialize all nodes to the ready state (STATUS=1) 2.Put the starting node A in Queue and change its status to the waiting state (STATUS=2) 3. [LOOP] Repeat steps 4 and 5 until queue is empty 4. Remove the front node N of Queue. Process N and change the status of N to the processed state (STATUS=3) 5. Add to the rear of queue all the neighbors of N that are in ready state (STATUS=1), and change their status to waiting state (STATUS=2). [End of Loop] 6. Exit
  • 12. A ED CB F 1.Initialize all nodes to the ready state (STATUS=1) 1 1 1 1 1 1 2.Put the starting node A in Queue and change its status to the waiting state (STATUS=2) A 2 1.Initialize all nodes to the ready state (STATUS=1) 2.Put the starting node A in Queue and change its status to the waiting state (STATUS=2) 3. [LOOP] Repeat steps 4 and 5 until queue is empty 4. Remove the front node N of Queue. Process N and change the status of N to the processed state (STATUS=3) 5. Add to the rear of queue all the neighbors of N that are in ready state (STATUS=1), and change their status to waiting state (STATUS=2). [End of Loop] 6. Exit 3 B C E 2 2 2 D F 3 2 2 3 3 3 3 B A C E D F Traversing order – A B C E D F
  • 13. Depth First Search (DFS) * DFS uses stack *During execution of algorithms , each node N of G will be in one of three states called status of N: - STATUS = 1(Ready state) - STATUS = 2(Waiting state) - STATUS= 3(Processed state) Logic
  • 14. A F D C E B 1.Initialize all nodes to the ready state (STATUS=1) 2.Push the starting node A onto stack and change its status to the waiting state (STATUS=2) 3. [LOOP] Repeat steps 4 and 5 until stack is empty 4. Pop the top node N of Stack. Process N and change the status of N to the processed state (STATUS=3) 5. Push onto Stack all the neighbors of N that are still in ready state (STATUS=1), and change their status to waiting state (STATUS=2). [End of Loop] 6. Exit Algorithm
  • 15. A F D C E B 1.Initialize all nodes to the ready state (STATUS=1) 1 1 11 1 1 2.Push the starting node A onto stack and change its status to the waiting state (STATUS=2) A 2 A 1.Initialize all nodes to the ready state (STATUS=1) 2.Push the starting node A onto stack and change its status to the waiting state (STATUS=2) 3. [LOOP] Repeat steps 4 and 5 until stack is empty 4. Pop the top node N of Stack. Process N and change the status of N to the processed state (STATUS=3) 5. Push onto Stack all the neighbors of N that are still in ready state (STATUS=1), and change their status to waiting state (STATUS=2). [End of Loop] 6. Exit A B C 3 2 2 C 3 D E 2 2 E 3 F 2 F 3 3 3 D B
  • 16. Traversing order is A C E F D B A C E F D B
  • 17. Thank you Jagjot singh chopra Shivam khanna 2016 csa 1569 2016csa1556