Professional Documents
Culture Documents
Lecture 2.3.1 Graph
Lecture 2.3.1 Graph
Lecture 2.3.1 Graph
ENGINEERING
DEPARTMENT OF COMPUTER
SCIENCE AND ENGG.
Bachelor of Engineering (Computer Science & Engineering)
DATA STRUCTURES CST-231
Prepared by: Er. Hatesh
COURSE OUTCOMES
CO Title Level
Number
CO1
2
A graph G consists of two sets
– a finite, nonempty set of vertices V(G)
https://tekslate.com/graphs-in-data-structures
3
of Vertices V
Set
Examples of Set of Edges E
GRAPHS
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:
https://www.tutorialride.com/data-structures/graphs-in-data-str
V = {A, B, C} ucture.htm
E = {(A, B), (A, C), (C, B)}
4
Graph
Representations
Graph is a data structure that consists of following
two components:
https://www.ebi.ac.uk/training/online/course/network-ana
lysis-protein-interaction-data-introduction/introduction-gra
ph-theory/graph-0
6
Adjacency List •.
7
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)).
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
•.
http://www.personal.kent.edu/~rmuhamma/GraphTheory/
MyGraphTheory/defEx.htm
10
•.
Degree
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
https://www.slideshare.net/aakashdeepsinghal/lecture-8-e
11
Connected •.
Component
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.
.
https://www.slideshare.net/angellaandrea/advanced-algori
thms-1-unionfind-on-disjointset-data-structures
12
Simple Path •.
13
Graph Traversal •.
https://www.youtube.com/watch?v=iaBEKo5sM7w
15
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.
16
Breadth First •.
Search
17
BFS
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