SlideShare a Scribd company logo
1 of 23
DISCOVER . LEARN . EMPOWER
GRAPHS
UNIVERSITY INSTITUTE OF
ENGINEERING
DEPARTMENT OF COMPUTER SCIENCE
AND ENGG.
Bachelor of Engineering (Computer Science & Engineering)
DATA STRUCTURES CST-231
Prepared by: Er. Hatesh
• https://www.thecrazyprogrammer.com/2
017/08/difference-between-tree-and-
graph.html
2
GRAPHS
CO
Number
Title Level
CO1 Able to develop applications using the graph data
structure.
Applying
CO2 Able to compare between different types of tree
data structures and use an appropriate data
structure for a design.
evaluating
CO3 Identify the strengths and weaknesses of different data
structures.
Analyzing
COURSE OUTCOMES
CO1
 A graph G consists of two sets
– a finite, nonempty set of vertices V(G)
– a finite, possible empty set of edges E(G)
– G(V,E) represents a graph
 An undirected graph is one in which the pair of vertices in a
edge is unordered, (v0, v1) = (v1,v0)
 A directed graph is one in which each edge is a directed pair of
vertices, <v0, v1> != <v1,v0>
A Graph is a non-linear data structure consisting
of nodes and edges.
The nodes are sometimes also referred to as
vertices and the edges are lines or arcs that
connect any two nodes in the graph. ...
Graphs are used to represent networks.
3
GRAPHS
https://tekslate.com/graphs-in-data-structures
in Facebook, each person is represented with a vertex or a
node. Each node is a structure and contains the information
like user id, user name, gender etc.
Graph 1:
V = {A, B, C, D, E, F}
E = {(A, B), (A, C), (B, C), (B, D), (D, E), (D, F), (E, F)}
Graph 2:
V = {A, B, C, D, E, F}
E = {(A, B), (A, C), (B, D), (C, E), (C, F)}
Graph 3:
V = {A, B, C}
E = {(A, B), (A, C), (C, B)}
4
Examples of
GRAPHS
https://www.tutorialride.com/data-structures/graphs-in-data-
structure.htm
Set of Vertices V
Set of Edges E
Graph is a data structure that consists of following
two components:
1. A finite set of vertices also called as nodes.
2. A finite set of ordered pair of the form (u, v)
called as edge.
The pair is ordered because (u, v) is not same as (v,
u) in case of a directed graph(di-graph). The pair of
the form (u, v) indicates that there is an edge from
vertex u to vertex v. The edges may contain
weight/value/cost.
s.
5
Graph
Representations
http://btechsmartclass.com/data_structures/graph-
representations.html/
An adjacency matrix is a square matrix used to
represent a finite graph.
In the special case of a finite simple graph, the
adjacency matrix is a (0,1) with zeros on its diagonal.
The adjacency matrix should be distinguished from the
incidence for a graph, a different matrix representation
whose elements indicate whether vertex–edge pairs are
incident or not, and degree.
6
Adjacency Matrix
https://www.ebi.ac.uk/training/online/course/network-
analysis-protein-interaction-data-
introduction/introduction-graph-theory/graph-0
• .
Adjacency list representations of graphs take a more
vertex-centric approach.
There are many possible implementations of adjacency
lists representation of graph.
Here we will implement it in 2 ways:- one using array of
vectors and another using vector of lists.
The representation of graph is implemented using
adjacency list. It makes use of STL(Standard Template
Library of C++)
7
Adjacency List
https://www.kodefork.com/articles/adjacency-list-graph-
representation-using-c-stl-in-competitive-programming/
• .
Graph Terminology
Vertex
A 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 (starting Vertex, ending Vertex). 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 edge is a bidirectional edge. If there is a undirected edge
between vertices A and B then edge (A , B) is equal to edge (B , A).
Directed Edge - A directed edge is a unidirectional edge. If there is a directed edge between
vertices A and B then edge (A , B) is not equal to edge (B , A).
Weighted Edge - A weighted edge is an edge with cost on it.
8
Graph Terminology
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 to have the same end vertices, and for two directed edges to have the
same origin and the same destination. Such edges are called parallel edges or multiple edges.
Self-loop
An edge (undirected or directed) is a self-loop if its two endpoints coincide.
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 alternating vertices and edges that starts at a vertex and ends at a vertex such that
each edge is incident to its predecessor and successor vertex.
http://www.csl.mtu.edu/cs2321/www/newLectures/24_Graph_Terminology.html
9
A vertex is incident to an edge if the vertex is one of
the two vertices the edge connects. Two distinct
incidences and are adjacent
10
Adjacent and
Incident
http://www.personal.kent.edu/~rmuhamma/GraphTheory/
MyGraphTheory/defEx.htm
• .
 The degree of a vertex is the number of edges
incident to that vertex
 For directed graph,
– the in-degree of a vertex v is the number of
edges
that have v as the head
– the out-degree of a vertex v is the number of
edges
that have v as the tail
11
Degree
https://www.slideshare.net/aakashdeepsinghal/lecture-8-e
• .
 A connected component of an undirected graph
is a maximal connected subgraph.
 A tree is a graph that is connected and acyclic.
 A directed graph is strongly connected if there
is a directed path from vi to vj and also
from vj to vi.
 A strongly connected component is a maximal
subgraph that is strongly connected.
.
12
Connected
Component
https://www.slideshare.net/angellaandrea/advanced-
algorithms-1-unionfind-on-disjointset-data-structures
• .
 A simple path is a path in which all vertices,
except possibly the first and the last, are distinct
 A cycle is a simple path in which the first and
the last vertices are the same
 In an undirected graph G, two vertices, v0 and v1,
are connected if there is a path in G from v0 to v1
 An undirected graph is connected if, for every
pair of distinct vertices vi, vj, there is a path
from vi to vj
13
Simple Path
http://www.algolist.net/Data_structures/Graph
• .
Graph traversal is technique used for searching a
vertex in a graph. The graph traversal is also used to
decide the order of vertices to be visit in the search
process. A graph traversal finds the egdes to be used
in the search process without creating loops that
means using graph traversal we visit all verticces of
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)
14
Graph Traversal
https://medium.com/basecs/going-broad-in-a-graph-bfs-
traversal-959bd1a09255
• .
Depth-first search is an algorithm for traversing or
searching tree or graph data structures.
The algorithm starts at the root node and explores as far
as possible along each branch before backtracking.
DFS for a graph is similar to Depth First Transversal Of A
tree. The only catch here is, unlike trees, graphs may
contain cycles, so we may come to the same node again.
15
Depth First Search
https://www.youtube.com/watch?v=iaBEKo5sM7w
• .
DFS
• DFS traversal of a graph, produces a spanning tree as final result. Spanning Tree is a graph without any loops.
• We use Stack data structure with maximum size of total number of vertices in the graph to implement DFS traversal of a
graph.
We use the following steps to implement DFS traversal...
• 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 adjacent vertex of the verex which is at top of the stack which is not visited and push it on to
the stack.
• Step 4: Repeat step 3 until there are no new vertex to be visit from the vertex on top of the stack.
• Step 5: When there is no new vertex to be 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
16
Breadth-first search (BFS) is an algorithm for traversing
or searching tree or graph data structures.
It starts at the tree root (or some arbitrary node of a
graph, sometimes referred to as a 'search key'), and
explores all of the neighbor nodes at the present depth
prior to moving on to the nodes at the next depth level.
It uses the opposite strategy as depth first search, which
instead explores the highest-depth nodes first before
being forced to backtrack and expand shallower nodes.
17
Breadth First
Search
https://artint.info/2e/html/ArtInt2e.Ch3.S5.SS1.html
• .
BFS
• BFS (Breadth First Search)
• BFS traversal of a graph, produces a spanning tree as final result. Spanning Tree is a graph without any loops. We
use Queue data structure with maximum size of total number of vertices in the graph to implement BFS traversal
of a graph.
We use the following steps to implement BFS traversal...
• 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 adjacent vertices of the verex which is at front of the Queue which is not visited and insert
them into the Queue.
• Step 4: When there is no new vertex to be visit from the vertex at front of the Queue then delete that vertex from
the Queue.
• Step 5: Repeat step 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
18
Advanced topics on Graphs
• Distances in graphs
• Disjoint Set
• Perfect Graphs
• Uniquely Partially Orderable Graphs
• Comparability Graphs
19
Assessment Pattern
• MST 1 -36 MARKS
• MST 2 -36 MARKS
• ELEMNT 1- Quiz- 12 MARKS
• ELEMENT 2 – ST – 9 MARKS
• ELEMENT 3 – assignment – 12 MARKS
• ELEMNET 4 – TUTE – 9 MARKS
• 6 MARKS FOR 90% ATTENDANCE
20
Applications
• Facebook: Each user is represented as a vertex and two people are friends when there is an edge between two vertices.
Similarly friend suggestion also uses graph theory concept.
• Google Maps: Various locations are represented as vertices and the roads are represented as edges and graph theory is
used to find shortest path between two nodes.
• Recommendations on e-commerce websites: The “Recommendations for you” section on various e-commerce websites
uses graph theory to recommend items of similar type to user’s choice.
• Graph theory is also used to study molecules in chemistry and physics.
21
REFERENCES
1. Lipschutz, Seymour, “Data Structures”, Schaum's Outline Series, Tata McGraw Hill.
2. Data structure and algorithm by Narasimha Karumanchi.
3. www.tutorialspoint.com
4. www.geeksforgeeks.com
5. Lipschutz, Seymour, “Data Structures”, Schaum's Outline Series, Tata McGraw Hill.
6. Gilberg/Forouzan,” Data Structure with C ,Cengage Learning.
7. Augenstein,Moshe J , Tanenbaum, Aaron M, “Data Structures using C and C++”, Prentice Hall of India.
8. Goodrich, Michael T., Tamassia, Roberto, and Mount, David M., “Data Structures and Algorithms in C++”, Wiley Student
Edition.
9. Aho, Alfred V., Ullman, Jeffrey D., Hopcroft ,John E. “Data Structures and Algorithms”, Addison Wesley
22
THANK YOU
For queries
Email: hatesh.cse@cumail.in

More Related Content

What's hot

Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsEhtisham Ali
 
Deterministic context free grammars &non-deterministic
Deterministic context free grammars &non-deterministicDeterministic context free grammars &non-deterministic
Deterministic context free grammars &non-deterministicLeyo Stephen
 
Attribute grammer
Attribute grammerAttribute grammer
Attribute grammerahmed51236
 
NLP_KASHK:Finite-State Morphological Parsing
NLP_KASHK:Finite-State Morphological ParsingNLP_KASHK:Finite-State Morphological Parsing
NLP_KASHK:Finite-State Morphological ParsingHemantha Kulathilake
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler DesignKuppusamy P
 
Lecture 3: Basic Concepts of Machine Learning - Induction & Evaluation
Lecture 3: Basic Concepts of Machine Learning - Induction & EvaluationLecture 3: Basic Concepts of Machine Learning - Induction & Evaluation
Lecture 3: Basic Concepts of Machine Learning - Induction & EvaluationMarina Santini
 
Advanced topics in artificial neural networks
Advanced topics in artificial neural networksAdvanced topics in artificial neural networks
Advanced topics in artificial neural networksswapnac12
 
Class imbalance problem1
Class imbalance problem1Class imbalance problem1
Class imbalance problem1chs71
 
Optimization/Gradient Descent
Optimization/Gradient DescentOptimization/Gradient Descent
Optimization/Gradient Descentkandelin
 
Deep Learning for Natural Language Processing
Deep Learning for Natural Language ProcessingDeep Learning for Natural Language Processing
Deep Learning for Natural Language ProcessingDevashish Shanker
 
Tree in Graph Theory in Discrete structure
Tree in Graph Theory in Discrete structure  Tree in Graph Theory in Discrete structure
Tree in Graph Theory in Discrete structure Rabin BK
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMSkoolkampus
 
Brief Introduction to Deep Learning + Solving XOR using ANNs
Brief Introduction to Deep Learning + Solving XOR using ANNsBrief Introduction to Deep Learning + Solving XOR using ANNs
Brief Introduction to Deep Learning + Solving XOR using ANNsAhmed Gad
 
An overview of gradient descent optimization algorithms
An overview of gradient descent optimization algorithms An overview of gradient descent optimization algorithms
An overview of gradient descent optimization algorithms Hakky St
 

What's hot (20)

Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Deterministic context free grammars &non-deterministic
Deterministic context free grammars &non-deterministicDeterministic context free grammars &non-deterministic
Deterministic context free grammars &non-deterministic
 
Computational Complexity
Computational ComplexityComputational Complexity
Computational Complexity
 
Attribute grammer
Attribute grammerAttribute grammer
Attribute grammer
 
NLP_KASHK:Finite-State Morphological Parsing
NLP_KASHK:Finite-State Morphological ParsingNLP_KASHK:Finite-State Morphological Parsing
NLP_KASHK:Finite-State Morphological Parsing
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler Design
 
Lecture 3: Basic Concepts of Machine Learning - Induction & Evaluation
Lecture 3: Basic Concepts of Machine Learning - Induction & EvaluationLecture 3: Basic Concepts of Machine Learning - Induction & Evaluation
Lecture 3: Basic Concepts of Machine Learning - Induction & Evaluation
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
StarGAN
StarGANStarGAN
StarGAN
 
Advanced topics in artificial neural networks
Advanced topics in artificial neural networksAdvanced topics in artificial neural networks
Advanced topics in artificial neural networks
 
K Nearest Neighbor Algorithm
K Nearest Neighbor AlgorithmK Nearest Neighbor Algorithm
K Nearest Neighbor Algorithm
 
Class imbalance problem1
Class imbalance problem1Class imbalance problem1
Class imbalance problem1
 
Optimization/Gradient Descent
Optimization/Gradient DescentOptimization/Gradient Descent
Optimization/Gradient Descent
 
Deep Learning for Natural Language Processing
Deep Learning for Natural Language ProcessingDeep Learning for Natural Language Processing
Deep Learning for Natural Language Processing
 
Tree in Graph Theory in Discrete structure
Tree in Graph Theory in Discrete structure  Tree in Graph Theory in Discrete structure
Tree in Graph Theory in Discrete structure
 
Unit 1 chapter 1 Design and Analysis of Algorithms
Unit 1   chapter 1 Design and Analysis of AlgorithmsUnit 1   chapter 1 Design and Analysis of Algorithms
Unit 1 chapter 1 Design and Analysis of Algorithms
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS
 
Brief Introduction to Deep Learning + Solving XOR using ANNs
Brief Introduction to Deep Learning + Solving XOR using ANNsBrief Introduction to Deep Learning + Solving XOR using ANNs
Brief Introduction to Deep Learning + Solving XOR using ANNs
 
Knn 160904075605-converted
Knn 160904075605-convertedKnn 160904075605-converted
Knn 160904075605-converted
 
An overview of gradient descent optimization algorithms
An overview of gradient descent optimization algorithms An overview of gradient descent optimization algorithms
An overview of gradient descent optimization algorithms
 

Similar to Lecture 2.3.1 Graph.pptx

Similar to Lecture 2.3.1 Graph.pptx (20)

Graphs
GraphsGraphs
Graphs
 
Spanningtreesppt
SpanningtreespptSpanningtreesppt
Spanningtreesppt
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
graph representation.pdf
graph representation.pdfgraph representation.pdf
graph representation.pdf
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
 
Graphs data structures
Graphs data structuresGraphs data structures
Graphs data structures
 
LEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdfLEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdf
 
NON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptxNON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptx
 
UNIT 4_DSA_KAVITHA_RMP.ppt
UNIT 4_DSA_KAVITHA_RMP.pptUNIT 4_DSA_KAVITHA_RMP.ppt
UNIT 4_DSA_KAVITHA_RMP.ppt
 
Talk on Graph Theory - I
Talk on Graph Theory - ITalk on Graph Theory - I
Talk on Graph Theory - I
 
Slides Chapter10.1 10.2
Slides Chapter10.1 10.2Slides Chapter10.1 10.2
Slides Chapter10.1 10.2
 
data structures and algorithms Unit 2
data structures and algorithms Unit 2data structures and algorithms Unit 2
data structures and algorithms Unit 2
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Graph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptxGraph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptx
 
VANU no sql ppt.pptx
VANU no sql ppt.pptxVANU no sql ppt.pptx
VANU no sql ppt.pptx
 
Vanmathy no sql
Vanmathy no sql Vanmathy no sql
Vanmathy no sql
 
Graphs in Data Structure
 Graphs in Data Structure Graphs in Data Structure
Graphs in Data Structure
 
ppt 1.pptx
ppt 1.pptxppt 1.pptx
ppt 1.pptx
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
 

Recently uploaded

DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Call Girls Mumbai
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptxrouholahahmadi9876
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxMuhammadAsimMuhammad6
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 
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
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...HenryBriggs2
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsvanyagupta248
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
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
 
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
 
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
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 

Recently uploaded (20)

DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
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
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
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
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
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
 
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
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
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
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 

Lecture 2.3.1 Graph.pptx

  • 1. DISCOVER . LEARN . EMPOWER GRAPHS UNIVERSITY INSTITUTE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGG. Bachelor of Engineering (Computer Science & Engineering) DATA STRUCTURES CST-231 Prepared by: Er. Hatesh
  • 2. • https://www.thecrazyprogrammer.com/2 017/08/difference-between-tree-and- graph.html 2 GRAPHS CO Number Title Level CO1 Able to develop applications using the graph data structure. Applying CO2 Able to compare between different types of tree data structures and use an appropriate data structure for a design. evaluating CO3 Identify the strengths and weaknesses of different data structures. Analyzing COURSE OUTCOMES CO1
  • 3.  A graph G consists of two sets – a finite, nonempty set of vertices V(G) – a finite, possible empty set of edges E(G) – G(V,E) represents a graph  An undirected graph is one in which the pair of vertices in a edge is unordered, (v0, v1) = (v1,v0)  A directed graph is one in which each edge is a directed pair of vertices, <v0, v1> != <v1,v0> A Graph is a non-linear data structure consisting of nodes and edges. The nodes are sometimes also referred to as vertices and the edges are lines or arcs that connect any two nodes in the graph. ... Graphs are used to represent networks. 3 GRAPHS https://tekslate.com/graphs-in-data-structures
  • 4. in Facebook, each person is represented with a vertex or a node. Each node is a structure and contains the information like user id, user name, gender etc. Graph 1: V = {A, B, C, D, E, F} E = {(A, B), (A, C), (B, C), (B, D), (D, E), (D, F), (E, F)} Graph 2: V = {A, B, C, D, E, F} E = {(A, B), (A, C), (B, D), (C, E), (C, F)} Graph 3: V = {A, B, C} E = {(A, B), (A, C), (C, B)} 4 Examples of GRAPHS https://www.tutorialride.com/data-structures/graphs-in-data- structure.htm Set of Vertices V Set of Edges E
  • 5. Graph is a data structure that consists of following two components: 1. A finite set of vertices also called as nodes. 2. A finite set of ordered pair of the form (u, v) called as edge. The pair is ordered because (u, v) is not same as (v, u) in case of a directed graph(di-graph). The pair of the form (u, v) indicates that there is an edge from vertex u to vertex v. The edges may contain weight/value/cost. s. 5 Graph Representations http://btechsmartclass.com/data_structures/graph- representations.html/
  • 6. An adjacency matrix is a square matrix used to represent a finite graph. In the special case of a finite simple graph, the adjacency matrix is a (0,1) with zeros on its diagonal. The adjacency matrix should be distinguished from the incidence for a graph, a different matrix representation whose elements indicate whether vertex–edge pairs are incident or not, and degree. 6 Adjacency Matrix https://www.ebi.ac.uk/training/online/course/network- analysis-protein-interaction-data- introduction/introduction-graph-theory/graph-0 • .
  • 7. Adjacency list representations of graphs take a more vertex-centric approach. There are many possible implementations of adjacency lists representation of graph. Here we will implement it in 2 ways:- one using array of vectors and another using vector of lists. The representation of graph is implemented using adjacency list. It makes use of STL(Standard Template Library of C++) 7 Adjacency List https://www.kodefork.com/articles/adjacency-list-graph- representation-using-c-stl-in-competitive-programming/ • .
  • 8. Graph Terminology Vertex A 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 (starting Vertex, ending Vertex). 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 edge is a bidirectional edge. If there is a undirected edge between vertices A and B then edge (A , B) is equal to edge (B , A). Directed Edge - A directed edge is a unidirectional edge. If there is a directed edge between vertices A and B then edge (A , B) is not equal to edge (B , A). Weighted Edge - A weighted edge is an edge with cost on it. 8
  • 9. Graph Terminology 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 to have the same end vertices, and for two directed edges to have the same origin and the same destination. Such edges are called parallel edges or multiple edges. Self-loop An edge (undirected or directed) is a self-loop if its two endpoints coincide. 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 alternating vertices and edges that starts at a vertex and ends at a vertex such that each edge is incident to its predecessor and successor vertex. http://www.csl.mtu.edu/cs2321/www/newLectures/24_Graph_Terminology.html 9
  • 10. A vertex is incident to an edge if the vertex is one of the two vertices the edge connects. Two distinct incidences and are adjacent 10 Adjacent and Incident http://www.personal.kent.edu/~rmuhamma/GraphTheory/ MyGraphTheory/defEx.htm • .
  • 11.  The degree of a vertex is the number of edges incident to that vertex  For directed graph, – the in-degree of a vertex v is the number of edges that have v as the head – the out-degree of a vertex v is the number of edges that have v as the tail 11 Degree https://www.slideshare.net/aakashdeepsinghal/lecture-8-e • .
  • 12.  A connected component of an undirected graph is a maximal connected subgraph.  A tree is a graph that is connected and acyclic.  A directed graph is strongly connected if there is a directed path from vi to vj and also from vj to vi.  A strongly connected component is a maximal subgraph that is strongly connected. . 12 Connected Component https://www.slideshare.net/angellaandrea/advanced- algorithms-1-unionfind-on-disjointset-data-structures • .
  • 13.  A simple path is a path in which all vertices, except possibly the first and the last, are distinct  A cycle is a simple path in which the first and the last vertices are the same  In an undirected graph G, two vertices, v0 and v1, are connected if there is a path in G from v0 to v1  An undirected graph is connected if, for every pair of distinct vertices vi, vj, there is a path from vi to vj 13 Simple Path http://www.algolist.net/Data_structures/Graph • .
  • 14. Graph traversal is technique used for searching a vertex in a graph. The graph traversal is also used to decide the order of vertices to be visit in the search process. A graph traversal finds the egdes to be used in the search process without creating loops that means using graph traversal we visit all verticces of 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) 14 Graph Traversal https://medium.com/basecs/going-broad-in-a-graph-bfs- traversal-959bd1a09255 • .
  • 15. Depth-first search is an algorithm for traversing or searching tree or graph data structures. The algorithm starts at the root node and explores as far as possible along each branch before backtracking. DFS for a graph is similar to Depth First Transversal Of A tree. The only catch here is, unlike trees, graphs may contain cycles, so we may come to the same node again. 15 Depth First Search https://www.youtube.com/watch?v=iaBEKo5sM7w • .
  • 16. DFS • DFS traversal of a graph, produces a spanning tree as final result. Spanning Tree is a graph without any loops. • We use Stack data structure with maximum size of total number of vertices in the graph to implement DFS traversal of a graph. We use the following steps to implement DFS traversal... • 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 adjacent vertex of the verex which is at top of the stack which is not visited and push it on to the stack. • Step 4: Repeat step 3 until there are no new vertex to be visit from the vertex on top of the stack. • Step 5: When there is no new vertex to be 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 16
  • 17. Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data structures. It starts at the tree root (or some arbitrary node of a graph, sometimes referred to as a 'search key'), and explores all of the neighbor nodes at the present depth prior to moving on to the nodes at the next depth level. It uses the opposite strategy as depth first search, which instead explores the highest-depth nodes first before being forced to backtrack and expand shallower nodes. 17 Breadth First Search https://artint.info/2e/html/ArtInt2e.Ch3.S5.SS1.html • .
  • 18. BFS • BFS (Breadth First Search) • BFS traversal of a graph, produces a spanning tree as final result. Spanning Tree is a graph without any loops. We use Queue data structure with maximum size of total number of vertices in the graph to implement BFS traversal of a graph. We use the following steps to implement BFS traversal... • 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 adjacent vertices of the verex which is at front of the Queue which is not visited and insert them into the Queue. • Step 4: When there is no new vertex to be visit from the vertex at front of the Queue then delete that vertex from the Queue. • Step 5: Repeat step 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 18
  • 19. Advanced topics on Graphs • Distances in graphs • Disjoint Set • Perfect Graphs • Uniquely Partially Orderable Graphs • Comparability Graphs 19
  • 20. Assessment Pattern • MST 1 -36 MARKS • MST 2 -36 MARKS • ELEMNT 1- Quiz- 12 MARKS • ELEMENT 2 – ST – 9 MARKS • ELEMENT 3 – assignment – 12 MARKS • ELEMNET 4 – TUTE – 9 MARKS • 6 MARKS FOR 90% ATTENDANCE 20
  • 21. Applications • Facebook: Each user is represented as a vertex and two people are friends when there is an edge between two vertices. Similarly friend suggestion also uses graph theory concept. • Google Maps: Various locations are represented as vertices and the roads are represented as edges and graph theory is used to find shortest path between two nodes. • Recommendations on e-commerce websites: The “Recommendations for you” section on various e-commerce websites uses graph theory to recommend items of similar type to user’s choice. • Graph theory is also used to study molecules in chemistry and physics. 21
  • 22. REFERENCES 1. Lipschutz, Seymour, “Data Structures”, Schaum's Outline Series, Tata McGraw Hill. 2. Data structure and algorithm by Narasimha Karumanchi. 3. www.tutorialspoint.com 4. www.geeksforgeeks.com 5. Lipschutz, Seymour, “Data Structures”, Schaum's Outline Series, Tata McGraw Hill. 6. Gilberg/Forouzan,” Data Structure with C ,Cengage Learning. 7. Augenstein,Moshe J , Tanenbaum, Aaron M, “Data Structures using C and C++”, Prentice Hall of India. 8. Goodrich, Michael T., Tamassia, Roberto, and Mount, David M., “Data Structures and Algorithms in C++”, Wiley Student Edition. 9. Aho, Alfred V., Ullman, Jeffrey D., Hopcroft ,John E. “Data Structures and Algorithms”, Addison Wesley 22
  • 23. THANK YOU For queries Email: hatesh.cse@cumail.in