SlideShare a Scribd company logo
Graphs MADE BY Zulkifal Yousaf [email_address]
Graph A data structure that consists of a set of nodes ( vertices ) and a set of edges that relate the nodes to each other The set of edges describes relationships among the vertices
Node:   Vertex point junction  Edge:   Give path.  TYPES OF GRAPHS:   1)Directed  2)Undirected
Undirected graphs When the edges in a graph have no direction, the graph is called  undirected edges do not have a direction (V1, V2) and (V2, V1) are the same edge
When the edges in a graph have a direction, the graph is called  directed  (or  digraph )   Directed graphs   E(Graph2) = {(1,3) (3,1) (5,9) (9,11) (5,7) edges have a direction  <V1, V2>  and  <V2, V1> are different edges
Graph implementation Array-based implementation A 1D array is used to represent the vertices A 2D array (adjacency matrix) is used to represent the edges
Array-based implementation
Linked-list implementation A 1D array is used to represent the vertices  A list is used for each vertex  v  which contains the vertices which are adjacent from  v  (adjacency list)
Linked-list implementation
Traversing a graph Where to start? Will all vertices be visited? How to prevent multiple visits?
Graph searching   Depth-First-Search (DFS) or Breadth-First-Search (BFS)
depth first traversal depthFirstTraversal (v) visit v mark v as visited for each neighbor (u) of v if not yet visited depthFirstTraversal (u)
Set found to false stack.Push(startVertex) DO stack.Pop(vertex) IF vertex == endVertex Set found to true ELSE Push all adjacent vertices onto stack WHILE !stack.IsEmpty() AND !found   IF(!found) Write &quot;Path does not exist&quot; Depth-First-Search (DFS)
Depth-First-Search (DFS) What is the idea behind DFS? Travel as far as you can down a path  DFS can be implemented efficiently using a  stack
start end (initialization)
 
 
Breadth-First-Searching (BFS) What is the idea behind BFS? Look at all possible paths at the same depth before you go at a deeper level
breadth first traversal Breadth First Traversal (v) put v in Q while Q not empty remove w from Q visit w mark w as visited for each neighbor (u) of w if not yet visited put u in Q
BFS can be implemented efficiently using a  queue Set found to false queue.Enqueue(startVertex) DO queue.Dequeue(vertex) IF vertex == endVertex Set found to true ELSE Enqueue all adjacent vertices onto queue WHILE !queue.IsEmpty() AND !found   Breadth-First-Searching (BFS)  IF(!found) Write &quot;Path does not exist&quot;  
start end (initialization)
next:
 
EXAMPLES OF GRAPHS IN OUR DAILY LIFE FACEBOOK ,TWITTER,OTHER SOCAIL NETWORKS
some problems that can be represented by a graph computer networks airline flights road map course prerequisite structure tasks for completing a job flow of control through a program many more
Types of Graphs SIMPLE GRAPH At most one edge between any pair of nodes.
Notation of graphs A graph  G  is defined as follows: G=(V,E) V(G):  a finite, nonempty set of vertices E(G):  a set of edges (pairs of vertices)
Multigraph Multiple edges between nodes are allowed
Pseudographs Self loops are permitted.
Trees are special cases of graphs!!   Trees vs graphs

More Related Content

What's hot (20)

PDF
Graph in Data Structure
Prof Ansari
 
PPT
Graphs in data structures
Savit Chandra
 
PPT
Data structure computer graphs
Kumar
 
PPTX
Graphss
fika sweety
 
PPT
Graphs in Data Structure
hafsa komal
 
PPTX
Graph in data structure
Abrish06
 
PPT
Chapter9 graph data structure
Mahmoud Alfarra
 
PPTX
Graphs in data structure
hamza javed
 
PPT
2.1 graph basic
Krish_ver2
 
PPTX
Data structure - Graph
Madhu Bala
 
PPT
Graphs in c language
SARITHA REDDY
 
PPTX
Application Of Graph Data Structure
Gaurang Dobariya
 
PPTX
Graphs
KomalPaliwal3
 
PDF
Skiena algorithm 2007 lecture10 graph data strctures
zukun
 
PPTX
Graph (Data structure)
shamiur rahman
 
PPTX
Data structures and algorithms lab7
Bianca Teşilă
 
PPTX
Matrix representation of graph
Rounak Biswas
 
PPT
Graphs bfs dfs
Jaya Gautam
 
PPTX
Data Structure Graph DMZ #DMZone
Doug Needham
 
Graph in Data Structure
Prof Ansari
 
Graphs in data structures
Savit Chandra
 
Data structure computer graphs
Kumar
 
Graphss
fika sweety
 
Graphs in Data Structure
hafsa komal
 
Graph in data structure
Abrish06
 
Chapter9 graph data structure
Mahmoud Alfarra
 
Graphs in data structure
hamza javed
 
2.1 graph basic
Krish_ver2
 
Data structure - Graph
Madhu Bala
 
Graphs in c language
SARITHA REDDY
 
Application Of Graph Data Structure
Gaurang Dobariya
 
Skiena algorithm 2007 lecture10 graph data strctures
zukun
 
Graph (Data structure)
shamiur rahman
 
Data structures and algorithms lab7
Bianca Teşilă
 
Matrix representation of graph
Rounak Biswas
 
Graphs bfs dfs
Jaya Gautam
 
Data Structure Graph DMZ #DMZone
Doug Needham
 

Viewers also liked (14)

PPTX
Jeremiasz bielawski
JerBie1994
 
PPT
Boresha Comp Plan Barbs Revisions
blindguy
 
PPTX
Claim Jumping - How to ripoff Obamacare
Craig J. Casey
 
PPTX
Bijverdienen door middel van de Deeleconomie
Rentsy
 
PPTX
Searching within a Website
Elisabeth White
 
PDF
Circuitos.en.corriente.continua
Uno Es
 
PDF
161213 信州 知の連携フォーラム
Kenya Hiraga
 
PDF
151112 library of the year 2015 えんぱーく
Kenya Hiraga
 
PPT
Nv presentation to doctors desk
Oleksii Sologub
 
PPT
Sterilization in orthodontics (4)
Indian dental academy
 
PPTX
Li-Fi Technology ( Advanced Technology in Future)
Daffodil International University
 
PPTX
Introduction to c programming language
sanjay joshi
 
PPTX
introduction to c programming language
sanjay joshi
 
Jeremiasz bielawski
JerBie1994
 
Boresha Comp Plan Barbs Revisions
blindguy
 
Claim Jumping - How to ripoff Obamacare
Craig J. Casey
 
Bijverdienen door middel van de Deeleconomie
Rentsy
 
Searching within a Website
Elisabeth White
 
Circuitos.en.corriente.continua
Uno Es
 
161213 信州 知の連携フォーラム
Kenya Hiraga
 
151112 library of the year 2015 えんぱーく
Kenya Hiraga
 
Nv presentation to doctors desk
Oleksii Sologub
 
Sterilization in orthodontics (4)
Indian dental academy
 
Li-Fi Technology ( Advanced Technology in Future)
Daffodil International University
 
Introduction to c programming language
sanjay joshi
 
introduction to c programming language
sanjay joshi
 
Ad

Similar to Graphs (20)

PPT
Graphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.ppt
babanazar7204
 
PPTX
WEB DEVELOPMET FRONT END WITH ADVANCED RECEAT
sahadevbkbiet2023
 
PPTX
Data structure Graph PPT ( BFS & DFS ) NOTES
sahadevbkbiet2023
 
PPT
Graphs (1)
Meet Patel
 
PDF
LEC 12-DSALGO-GRAPHS(final12).pdf
MuhammadUmerIhtisham
 
PPT
Graphs concept in data structures and algorithms.ppt
vimalak8
 
PPTX
Data Structure and algorithms - Graph1.pptx
Kishor767966
 
PPT
Graphs
Saurabh Mishra
 
PPT
14. GRAPH in data structures and algorithm.ppt
saurabhthege
 
PPT
Graphs.ppt of mathemaics we have to clar all doubts
nc3186331
 
PPT
Graphs.ppt
lakshmi26355
 
PPT
Unit VI - Graphs.ppt
HODElex
 
PPTX
Graph data structures for ppt for understanding.pptx
ramkumar649780
 
PPTX
Data Structures and Agorithm: DS 21 Graph Theory.pptx
RashidFaridChishti
 
PPT
Graphs
LavanyaJ28
 
PDF
Graphhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdf
timoemin50
 
PPTX
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
VISWANATHAN R V
 
PPTX
DATA STRUCTURES.pptx
KENNEDY GITHAIGA
 
PPTX
logic.pptx
KENNEDY GITHAIGA
 
Graphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.ppt
babanazar7204
 
WEB DEVELOPMET FRONT END WITH ADVANCED RECEAT
sahadevbkbiet2023
 
Data structure Graph PPT ( BFS & DFS ) NOTES
sahadevbkbiet2023
 
Graphs (1)
Meet Patel
 
LEC 12-DSALGO-GRAPHS(final12).pdf
MuhammadUmerIhtisham
 
Graphs concept in data structures and algorithms.ppt
vimalak8
 
Data Structure and algorithms - Graph1.pptx
Kishor767966
 
14. GRAPH in data structures and algorithm.ppt
saurabhthege
 
Graphs.ppt of mathemaics we have to clar all doubts
nc3186331
 
Graphs.ppt
lakshmi26355
 
Unit VI - Graphs.ppt
HODElex
 
Graph data structures for ppt for understanding.pptx
ramkumar649780
 
Data Structures and Agorithm: DS 21 Graph Theory.pptx
RashidFaridChishti
 
Graphs
LavanyaJ28
 
Graphhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdf
timoemin50
 
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
VISWANATHAN R V
 
DATA STRUCTURES.pptx
KENNEDY GITHAIGA
 
logic.pptx
KENNEDY GITHAIGA
 
Ad

More from Zulkifal Yousaf (16)

PDF
Viral molecular genetics
Zulkifal Yousaf
 
PPT
Cytogenetics
Zulkifal Yousaf
 
PDF
Epigenetics
Zulkifal Yousaf
 
PPT
Cloning
Zulkifal Yousaf
 
DOCX
Developmental genetics
Zulkifal Yousaf
 
PPT
fertilization
Zulkifal Yousaf
 
PPT
Arab Isreal conflicts
Zulkifal Yousaf
 
PPTX
Physiological Development Of Children Engaged In Child Labor...........1
Zulkifal Yousaf
 
PPT
Communication skills
Zulkifal Yousaf
 
DOC
dna and rna Viruses
Zulkifal Yousaf
 
DOCX
Globalization
Zulkifal Yousaf
 
DOC
Pakistan Ordinance Factory
Zulkifal Yousaf
 
PPTX
Dna Viruses
Zulkifal Yousaf
 
PPT
Child Labour
Zulkifal Yousaf
 
PPT
Long Reports
Zulkifal Yousaf
 
PPTX
Communication Barriers Between Teacher And Student
Zulkifal Yousaf
 
Viral molecular genetics
Zulkifal Yousaf
 
Cytogenetics
Zulkifal Yousaf
 
Epigenetics
Zulkifal Yousaf
 
Developmental genetics
Zulkifal Yousaf
 
fertilization
Zulkifal Yousaf
 
Arab Isreal conflicts
Zulkifal Yousaf
 
Physiological Development Of Children Engaged In Child Labor...........1
Zulkifal Yousaf
 
Communication skills
Zulkifal Yousaf
 
dna and rna Viruses
Zulkifal Yousaf
 
Globalization
Zulkifal Yousaf
 
Pakistan Ordinance Factory
Zulkifal Yousaf
 
Dna Viruses
Zulkifal Yousaf
 
Child Labour
Zulkifal Yousaf
 
Long Reports
Zulkifal Yousaf
 
Communication Barriers Between Teacher And Student
Zulkifal Yousaf
 

Recently uploaded (20)

PDF
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
PDF
The Past, Present & Future of Kenya's Digital Transformation
Moses Kemibaro
 
PDF
Per Axbom: The spectacular lies of maps
Nexer Digital
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PPTX
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
PDF
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Lecture A - AI Workflows for Banking.pdf
Dr. LAM Yat-fai (林日辉)
 
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
The Past, Present & Future of Kenya's Digital Transformation
Moses Kemibaro
 
Per Axbom: The spectacular lies of maps
Nexer Digital
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Lecture A - AI Workflows for Banking.pdf
Dr. LAM Yat-fai (林日辉)
 

Graphs

  • 1. Graphs MADE BY Zulkifal Yousaf [email_address]
  • 2. Graph A data structure that consists of a set of nodes ( vertices ) and a set of edges that relate the nodes to each other The set of edges describes relationships among the vertices
  • 3. Node: Vertex point junction Edge: Give path. TYPES OF GRAPHS: 1)Directed 2)Undirected
  • 4. Undirected graphs When the edges in a graph have no direction, the graph is called undirected edges do not have a direction (V1, V2) and (V2, V1) are the same edge
  • 5. When the edges in a graph have a direction, the graph is called directed (or digraph ) Directed graphs E(Graph2) = {(1,3) (3,1) (5,9) (9,11) (5,7) edges have a direction <V1, V2> and <V2, V1> are different edges
  • 6. Graph implementation Array-based implementation A 1D array is used to represent the vertices A 2D array (adjacency matrix) is used to represent the edges
  • 8. Linked-list implementation A 1D array is used to represent the vertices A list is used for each vertex v which contains the vertices which are adjacent from v (adjacency list)
  • 10. Traversing a graph Where to start? Will all vertices be visited? How to prevent multiple visits?
  • 11. Graph searching Depth-First-Search (DFS) or Breadth-First-Search (BFS)
  • 12. depth first traversal depthFirstTraversal (v) visit v mark v as visited for each neighbor (u) of v if not yet visited depthFirstTraversal (u)
  • 13. Set found to false stack.Push(startVertex) DO stack.Pop(vertex) IF vertex == endVertex Set found to true ELSE Push all adjacent vertices onto stack WHILE !stack.IsEmpty() AND !found   IF(!found) Write &quot;Path does not exist&quot; Depth-First-Search (DFS)
  • 14. Depth-First-Search (DFS) What is the idea behind DFS? Travel as far as you can down a path DFS can be implemented efficiently using a stack
  • 16.  
  • 17.  
  • 18. Breadth-First-Searching (BFS) What is the idea behind BFS? Look at all possible paths at the same depth before you go at a deeper level
  • 19. breadth first traversal Breadth First Traversal (v) put v in Q while Q not empty remove w from Q visit w mark w as visited for each neighbor (u) of w if not yet visited put u in Q
  • 20. BFS can be implemented efficiently using a queue Set found to false queue.Enqueue(startVertex) DO queue.Dequeue(vertex) IF vertex == endVertex Set found to true ELSE Enqueue all adjacent vertices onto queue WHILE !queue.IsEmpty() AND !found   Breadth-First-Searching (BFS) IF(!found) Write &quot;Path does not exist&quot;  
  • 22. next:
  • 23.  
  • 24. EXAMPLES OF GRAPHS IN OUR DAILY LIFE FACEBOOK ,TWITTER,OTHER SOCAIL NETWORKS
  • 25. some problems that can be represented by a graph computer networks airline flights road map course prerequisite structure tasks for completing a job flow of control through a program many more
  • 26. Types of Graphs SIMPLE GRAPH At most one edge between any pair of nodes.
  • 27. Notation of graphs A graph G is defined as follows: G=(V,E) V(G): a finite, nonempty set of vertices E(G): a set of edges (pairs of vertices)
  • 28. Multigraph Multiple edges between nodes are allowed
  • 29. Pseudographs Self loops are permitted.
  • 30. Trees are special cases of graphs!! Trees vs graphs