SlideShare a Scribd company logo
UNIT-IV
GRAPH
Basic Concepts
 a) Graph
 A Graph G(V, E) consists of two sets
 A set V, called set of all vertices or nodes
 A set E, called set of all edges.
 An edge e = (v, w) is a pair of vertices v and w and is said to be
path between v and w. Figure 1 shows a graph for which there
are five vertices and five edges.
 V = {v1, v2, v3, v4, v5}
 and E = {e1, e2, e3, e4, e5}
 Directed Graph
 Degree of Vertex: The number of edges connected
with vertex v is called the degree of vertex v, and
is denoted by degree(v). But for a digraph, there
are two degrees: indegree and outdegree
 Acyclic Graph
 Adjacent Vertices
 Self loop
 Parallel Edges
 Simple Graph (digraph)
 Complete Graph: A graph (digraph) is said to be complete
if each vertex vi, is adjacent to every other vertex vj in a
graph, In other words, there are edges from any vertex to
all other ver
 Isolated Vertex: A vertex is isolated if there is no edge
connected from any other vertex to the vertex.
 Weighted Graph: A graph (or digraph) is termed as
weighted graph if all the edges in it are labeled with some
weights
 Connected Graph: In a graph (not digraph) G, two vertices
vi and vj are said to be connected if there is a path in G
from vi to vj (or vi to vj)
Representation of Graphs in Memory
 Adjacency Matrix
 Matrix representation is the most useful way of representing any
graph. This representation uses a square matrix of order n  n, n
being the number of vertices in the graph. Entries in the matrix
can be decided as follows:
 This matrix is known as adjacency because n entry stores the
information whether two vertices are adjacent or not. Also the
matrix is alternatively termed as bit matrix o Boolean matrix as
the entries are either 0 or 1.
 Adjacency matrix is also useful to store multigraph and weighted
graph. In case of multigraph representation instead of entry 1, the
entry will be the number of edges between two vertices. And is
case of weighted graph, the entries are weighted of the edges
between the vertices instead of 0 or 1
Drawback of Adjacency Matrix
Representation
 Difficult to insert and delete nodes in G. This is
because the size of A may need to be changed
and the nodes may need to be reordered, so
there may be many changes in the matrix A.
 If the number of edges is O(m) or O(m log2 m),
then the matrix A will be sparse; hence a large
space will be wasted
UNIT-VIQueueQueueQueueQueueQueueQueueQueueQueue.pptx
UNIT-VIQueueQueueQueueQueueQueueQueueQueueQueue.pptx
Path Matrix
Finding Path Matrix
Linked Representation of a Graph
 The linked representation will contain two lists:
 A node list NODE and
 A edge list EDGE
UNIT-VIQueueQueueQueueQueueQueueQueueQueueQueue.pptx
UNIT-VIQueueQueueQueueQueueQueueQueueQueueQueue.pptx
UNIT-VIQueueQueueQueueQueueQueueQueueQueueQueue.pptx
Shortest Path Problem
 Shortest path problem of a graph is about finding
a path between two vertices in such a way that
this path will satisfy some criteria of
optimization. For example, for a non-weighted
graph, the number of edges will be minimum
and for weighted graph, the sum of weights on
all edges in the path will be minimum. A few
important algorithms are Warshall's algorithm,
Floyd's algorithm and Dijkstra's algorithm.
Warshall's algorithm
UNIT-VIQueueQueueQueueQueueQueueQueueQueueQueue.pptx
UNIT-VIQueueQueueQueueQueueQueueQueueQueueQueue.pptx
UNIT-VIQueueQueueQueueQueueQueueQueueQueueQueue.pptx
UNIT-VIQueueQueueQueueQueueQueueQueueQueueQueue.pptx
Traversing a Graph
 Depth-First Search(DFS)
 DFS traversal is similar to the inorder traversal
of a tree. It begins at vertex v, then visit the
vertex v first. Then visit all the vertices along a
path which begins at v. This means that, visit the
vertex v then the vertex immediate adjacent to v,
let it be vx. Next, if vx has an immediate adjacent
vy, then visit it and so on, till there is a 'dead end'.
This results a path P, v – vx – vy.
UNIT-VIQueueQueueQueueQueueQueueQueueQueueQueue.pptx
UNIT-VIQueueQueueQueueQueueQueueQueueQueueQueue.pptx
Breadth-First Search(BFS)
UNIT-VIQueueQueueQueueQueueQueueQueueQueueQueue.pptx

More Related Content

PPTX
Graphs aktu notes computer networks.pptx
PDF
unit-3-dsa-graph introduction to grapgh and graph type
PPT
graph ASS (1).ppt
PPT
Lecture 5b graphs and hashing
PPTX
Graph terminology and algorithm and tree.pptx
PPT
graphass1-23022111180722548-1ba6b00a.ppt
PPTX
Graph ASS DBATU.pptx
PPT
Graphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.ppt
Graphs aktu notes computer networks.pptx
unit-3-dsa-graph introduction to grapgh and graph type
graph ASS (1).ppt
Lecture 5b graphs and hashing
Graph terminology and algorithm and tree.pptx
graphass1-23022111180722548-1ba6b00a.ppt
Graph ASS DBATU.pptx
Graphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.ppt

Similar to UNIT-VIQueueQueueQueueQueueQueueQueueQueueQueue.pptx (20)

PDF
Graphs.pdf
PPTX
Graphs.pptx
PPTX
Data Structure of computer science and technology
PPT
Graphs
PPTX
Data structure - Graph
PPTX
Graph in data structure
PDF
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
PPT
Graph theory concepts complex networks presents-rouhollah nabati
PPTX
PPTX
Graph data structures for ppt for understanding.pptx
PPTX
Graph Theory in Theoretical computer science
PPSX
Unit-6 Graph.ppsx ppt
DOCX
Ass. (3)graph d.m
PPT
Graph theory
PPTX
Chapter 6-DS(Introduction to Graph and its terminologies).pptx
PDF
09_DS_MCA_Graphs.pdf
PPT
graph.ppt
PPTX
Elements of Graph Theory for IS.pptx
Graphs.pdf
Graphs.pptx
Data Structure of computer science and technology
Graphs
Data structure - Graph
Graph in data structure
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Graph theory concepts complex networks presents-rouhollah nabati
Graph data structures for ppt for understanding.pptx
Graph Theory in Theoretical computer science
Unit-6 Graph.ppsx ppt
Ass. (3)graph d.m
Graph theory
Chapter 6-DS(Introduction to Graph and its terminologies).pptx
09_DS_MCA_Graphs.pdf
graph.ppt
Elements of Graph Theory for IS.pptx
Ad

More from nakshpub (7)

PPT
Integrated Fundamental and Technical Analysis of Select Public Sector Oil Com...
PPT
Predicting Stock Market Trends Using Machine Learning and Deep Learning Algor...
PPT
Chapter 5Electronic MailElectronic Mail.ppt
PPT
Chapter 4Application AuthonicationApplication Authonication.ppt
PPT
Chapter 3CrypotgraphyCrypotgraphyCrypotgraphy.ppt
PPT
Chapter 7Web SecurityWeb SecurityWeb Security.ppt
PPTX
Unit-VStackStackStackStackStackStack.pptx
Integrated Fundamental and Technical Analysis of Select Public Sector Oil Com...
Predicting Stock Market Trends Using Machine Learning and Deep Learning Algor...
Chapter 5Electronic MailElectronic Mail.ppt
Chapter 4Application AuthonicationApplication Authonication.ppt
Chapter 3CrypotgraphyCrypotgraphyCrypotgraphy.ppt
Chapter 7Web SecurityWeb SecurityWeb Security.ppt
Unit-VStackStackStackStackStackStack.pptx
Ad

Recently uploaded (20)

PPTX
Sustainable Sites - Green Building Construction
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
Well-logging-methods_new................
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
DOCX
573137875-Attendance-Management-System-original
PPTX
web development for engineering and engineering
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Digital Logic Computer Design lecture notes
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
Lecture Notes Electrical Wiring System Components
Sustainable Sites - Green Building Construction
Operating System & Kernel Study Guide-1 - converted.pdf
Model Code of Practice - Construction Work - 21102022 .pdf
Well-logging-methods_new................
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
573137875-Attendance-Management-System-original
web development for engineering and engineering
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
bas. eng. economics group 4 presentation 1.pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Digital Logic Computer Design lecture notes
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Lecture Notes Electrical Wiring System Components

UNIT-VIQueueQueueQueueQueueQueueQueueQueueQueue.pptx

  • 2. Basic Concepts  a) Graph  A Graph G(V, E) consists of two sets  A set V, called set of all vertices or nodes  A set E, called set of all edges.  An edge e = (v, w) is a pair of vertices v and w and is said to be path between v and w. Figure 1 shows a graph for which there are five vertices and five edges.  V = {v1, v2, v3, v4, v5}  and E = {e1, e2, e3, e4, e5}
  • 3.  Directed Graph  Degree of Vertex: The number of edges connected with vertex v is called the degree of vertex v, and is denoted by degree(v). But for a digraph, there are two degrees: indegree and outdegree  Acyclic Graph  Adjacent Vertices  Self loop  Parallel Edges  Simple Graph (digraph)
  • 4.  Complete Graph: A graph (digraph) is said to be complete if each vertex vi, is adjacent to every other vertex vj in a graph, In other words, there are edges from any vertex to all other ver  Isolated Vertex: A vertex is isolated if there is no edge connected from any other vertex to the vertex.  Weighted Graph: A graph (or digraph) is termed as weighted graph if all the edges in it are labeled with some weights  Connected Graph: In a graph (not digraph) G, two vertices vi and vj are said to be connected if there is a path in G from vi to vj (or vi to vj)
  • 5. Representation of Graphs in Memory  Adjacency Matrix  Matrix representation is the most useful way of representing any graph. This representation uses a square matrix of order n  n, n being the number of vertices in the graph. Entries in the matrix can be decided as follows:  This matrix is known as adjacency because n entry stores the information whether two vertices are adjacent or not. Also the matrix is alternatively termed as bit matrix o Boolean matrix as the entries are either 0 or 1.  Adjacency matrix is also useful to store multigraph and weighted graph. In case of multigraph representation instead of entry 1, the entry will be the number of edges between two vertices. And is case of weighted graph, the entries are weighted of the edges between the vertices instead of 0 or 1
  • 6. Drawback of Adjacency Matrix Representation  Difficult to insert and delete nodes in G. This is because the size of A may need to be changed and the nodes may need to be reordered, so there may be many changes in the matrix A.  If the number of edges is O(m) or O(m log2 m), then the matrix A will be sparse; hence a large space will be wasted
  • 11. Linked Representation of a Graph  The linked representation will contain two lists:  A node list NODE and  A edge list EDGE
  • 15. Shortest Path Problem  Shortest path problem of a graph is about finding a path between two vertices in such a way that this path will satisfy some criteria of optimization. For example, for a non-weighted graph, the number of edges will be minimum and for weighted graph, the sum of weights on all edges in the path will be minimum. A few important algorithms are Warshall's algorithm, Floyd's algorithm and Dijkstra's algorithm.
  • 21. Traversing a Graph  Depth-First Search(DFS)  DFS traversal is similar to the inorder traversal of a tree. It begins at vertex v, then visit the vertex v first. Then visit all the vertices along a path which begins at v. This means that, visit the vertex v then the vertex immediate adjacent to v, let it be vx. Next, if vx has an immediate adjacent vy, then visit it and so on, till there is a 'dead end'. This results a path P, v – vx – vy.