SlideShare a Scribd company logo
1 of 22
Graphs
What is a 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
Formal definition 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)
Directed vs. undirected graphs
• 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 (or digraph)
Directed vs. undirected graphs
(cont.)
E(Graph2) = {(1,3) (3,1) (5,9) (9,11)
(5,7)
Warning: if the graph is
directed, the order of the
vertices in each edge is
important !!
• Trees are special cases of graphs!!
Trees vs graphs
Graph terminology
• 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
• Complete graph: a graph in which every
vertex is directly connected to every other
vertex
5 is adjacent to 7
7 is adjacent from 5
• What is the number of edges in a complete
directed graph with N vertices?
N * (N-1)
Graph terminology (cont.)
• What is the number of edges in a complete
undirected graph with N vertices?
N * (N-1) / 2
Graph terminology (cont.)
Graph terminology (cont.)
• Multi-graph
• Cycle
• Loop
• Weighted graph: a graph in which each edge
carries a value
Graph terminology (cont.)
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-
Adjacency Matrix
Graph implementation (cont.)
• 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
Adjacency Matrix for Un-
Weighted Graphs
1. Adjacency Matrix
2. Matrix for edges
3. Matrix for 2 length paths
4. Matrix for 3 length paths
5. Matrix for n length paths
6. Path Matrix
7. Completely Connected Graph
Graph searching
• Problem: find a path between two nodes of
the graph (e.g., Austin and Washington)
• Methods: Depth-First-Search (DFS) or
Breadth-First-Search (BFS)
Depth-First-Search (DFS)
• What is the idea behind DFS?
– Travel as far as you can down a path
– Back up as little as possible when you reach a
"dead end" (i.e., next vertex has been "marked"
or there is no next vertex)
• DFS can be implemented efficiently using a
stack
DFS
• Algorithm:
Starting Node is A
1. Initialize all nodes to ready state(Status=1)
2. Push starting nose A onto Stack and change its status to
waiting state (Status=2).
3.Repeat steps 4 & 5 until STACK is empty.
4. Pop Top node N. Process N and change its Status to the processed
state (Status=3).
5.Push onto Stack all the neighbors of N that are still in ready state
and change their state as waiting state(State=2).
6. Exit.
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
– Back up as far as possible when you reach a
"dead end" (i.e., next vertex has been "marked"
or there is no next vertex)
BFS
• Algorithm:
Starting Node is A
1. Initialize all nodes to ready state(Status=1)
2. Push starting nose A onto Queue and change its status to
waiting state (Status=2).
3.Repeat steps 4 & 5 until Queue is empty.
4. Remove the front node N. Process N and change its Status to the
processed state (Status=3).
5.Add to the rear of Queue all the neighbors of N that are still in
ready state and change their state to waiting (State=2).
6. Exit.
• Examples of Both DFS & BFS.

More Related Content

What's hot (20)

Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
 
Lecture8 data structure(graph)
Lecture8 data structure(graph)Lecture8 data structure(graph)
Lecture8 data structure(graph)
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
Graph Theory Introduction
Graph Theory IntroductionGraph Theory Introduction
Graph Theory Introduction
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in data structure
 
Graph isomorphism
Graph isomorphismGraph isomorphism
Graph isomorphism
 
Graph theory presentation
Graph theory presentationGraph theory presentation
Graph theory presentation
 
Graph Theory: Trees
Graph Theory: TreesGraph Theory: Trees
Graph Theory: Trees
 
Graph Theory: Matrix representation of graphs
Graph Theory: Matrix representation of graphsGraph Theory: Matrix representation of graphs
Graph Theory: Matrix representation of graphs
 
Slides Chapter10.1 10.2
Slides Chapter10.1 10.2Slides Chapter10.1 10.2
Slides Chapter10.1 10.2
 
Topological Sorting
Topological SortingTopological Sorting
Topological Sorting
 
Ppt of graph theory
Ppt of graph theoryPpt of graph theory
Ppt of graph theory
 
Euler graph
Euler graphEuler graph
Euler graph
 
Graphs in datastructures
Graphs in datastructuresGraphs in datastructures
Graphs in datastructures
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structure
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Graphs data structures
Graphs data structuresGraphs data structures
Graphs data structures
 
Tree and graph
Tree and graphTree and graph
Tree and graph
 

Viewers also liked

Graph in data structure
Graph in data structureGraph in data structure
Graph in data structureAbrish06
 
Graph representation
Graph representationGraph representation
Graph representationTech_MX
 
Graph data structure
Graph data structureGraph data structure
Graph data structureTech_MX
 
Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of GraphAbhishek Pachisia
 
Trees data structure
Trees data structureTrees data structure
Trees data structureSumit Gupta
 
Graph theory 1
Graph theory 1Graph theory 1
Graph theory 1Tech_MX
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURESbca2010
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and GraphsIntro C# Book
 
Data Structures, Graphs
Data Structures, GraphsData Structures, Graphs
Data Structures, GraphsJibrael Jos
 
Data structure introduction
Data structure introductionData structure introduction
Data structure introductionramyasanthosh
 
Graphs in data structures
Graphs in data structuresGraphs in data structures
Graphs in data structuresSavit Chandra
 
Path cycle part1
Path cycle part1Path cycle part1
Path cycle part1guestb63941
 
Test Case Management with MTM 2013
Test Case Management with MTM 2013Test Case Management with MTM 2013
Test Case Management with MTM 2013Raluca Suditu
 
Graph Processing with Apache TinkerPop
Graph Processing with Apache TinkerPopGraph Processing with Apache TinkerPop
Graph Processing with Apache TinkerPopJason Plurad
 
Software Verification, Validation and Testing
Software Verification, Validation and TestingSoftware Verification, Validation and Testing
Software Verification, Validation and TestingDr Sukhpal Singh Gill
 
Test design techniques: Structured and Experienced-based techniques
Test design techniques: Structured and Experienced-based techniquesTest design techniques: Structured and Experienced-based techniques
Test design techniques: Structured and Experienced-based techniquesKhuong Nguyen
 

Viewers also liked (20)

Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]
 
Graph representation
Graph representationGraph representation
Graph representation
 
Graph data structure
Graph data structureGraph data structure
Graph data structure
 
Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of Graph
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Graph theory 1
Graph theory 1Graph theory 1
Graph theory 1
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
 
Data Structures, Graphs
Data Structures, GraphsData Structures, Graphs
Data Structures, Graphs
 
Graphss
GraphssGraphss
Graphss
 
Data structure introduction
Data structure introductionData structure introduction
Data structure introduction
 
Graphs in data structures
Graphs in data structuresGraphs in data structures
Graphs in data structures
 
Graphs
GraphsGraphs
Graphs
 
Test cases
Test casesTest cases
Test cases
 
Path cycle part1
Path cycle part1Path cycle part1
Path cycle part1
 
Test Case Management with MTM 2013
Test Case Management with MTM 2013Test Case Management with MTM 2013
Test Case Management with MTM 2013
 
Graph Processing with Apache TinkerPop
Graph Processing with Apache TinkerPopGraph Processing with Apache TinkerPop
Graph Processing with Apache TinkerPop
 
Software Verification, Validation and Testing
Software Verification, Validation and TestingSoftware Verification, Validation and Testing
Software Verification, Validation and Testing
 
Test design techniques: Structured and Experienced-based techniques
Test design techniques: Structured and Experienced-based techniquesTest design techniques: Structured and Experienced-based techniques
Test design techniques: Structured and Experienced-based techniques
 

Similar to Data structure computer graphs

Similar to Data structure computer graphs (20)

LEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdfLEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdf
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
 
Data structure
Data structureData structure
Data structure
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
ppt 1.pptx
ppt 1.pptxppt 1.pptx
ppt 1.pptx
 
Graphs (1)
Graphs (1)Graphs (1)
Graphs (1)
 
Unit ix graph
Unit   ix    graph Unit   ix    graph
Unit ix graph
 
Unit 9 graph
Unit   9 graphUnit   9 graph
Unit 9 graph
 
Graphs
GraphsGraphs
Graphs
 
Graphs.ppt
Graphs.pptGraphs.ppt
Graphs.ppt
 
Graphs.ppt of mathemaics we have to clar all doubts
Graphs.ppt of mathemaics  we have to clar all doubtsGraphs.ppt of mathemaics  we have to clar all doubts
Graphs.ppt of mathemaics we have to clar all doubts
 
6. Graphs
6. Graphs6. Graphs
6. Graphs
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
 
Unit V - ppt.pptx
Unit V - ppt.pptxUnit V - ppt.pptx
Unit V - ppt.pptx
 
Graphs
GraphsGraphs
Graphs
 
Graphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ programGraphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ program
 
UNIT III.pptx
UNIT III.pptxUNIT III.pptx
UNIT III.pptx
 
U1 L5 DAA.pdf
U1 L5 DAA.pdfU1 L5 DAA.pdf
U1 L5 DAA.pdf
 
GRAPH - DISCRETE STRUCTURE AND ALGORITHM
GRAPH - DISCRETE STRUCTURE AND ALGORITHMGRAPH - DISCRETE STRUCTURE AND ALGORITHM
GRAPH - DISCRETE STRUCTURE AND ALGORITHM
 

More from Kumar

Graphics devices
Graphics devicesGraphics devices
Graphics devicesKumar
 
Fill area algorithms
Fill area algorithmsFill area algorithms
Fill area algorithmsKumar
 
region-filling
region-fillingregion-filling
region-fillingKumar
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivationKumar
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons dericationKumar
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xsltKumar
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xmlKumar
 
Xml basics
Xml basicsXml basics
Xml basicsKumar
 
XML Schema
XML SchemaXML Schema
XML SchemaKumar
 
Publishing xml
Publishing xmlPublishing xml
Publishing xmlKumar
 
Applying xml
Applying xmlApplying xml
Applying xmlKumar
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XMLKumar
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee applicationKumar
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLKumar
 
EJB Fundmentals
EJB FundmentalsEJB Fundmentals
EJB FundmentalsKumar
 
JSP and struts programming
JSP and struts programmingJSP and struts programming
JSP and struts programmingKumar
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programmingKumar
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversKumar
 
Introduction to J2EE
Introduction to J2EEIntroduction to J2EE
Introduction to J2EEKumar
 

More from Kumar (20)

Graphics devices
Graphics devicesGraphics devices
Graphics devices
 
Fill area algorithms
Fill area algorithmsFill area algorithms
Fill area algorithms
 
region-filling
region-fillingregion-filling
region-filling
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xslt
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xml
 
Xml basics
Xml basicsXml basics
Xml basics
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Publishing xml
Publishing xmlPublishing xml
Publishing xml
 
DTD
DTDDTD
DTD
 
Applying xml
Applying xmlApplying xml
Applying xml
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee application
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XML
 
EJB Fundmentals
EJB FundmentalsEJB Fundmentals
EJB Fundmentals
 
JSP and struts programming
JSP and struts programmingJSP and struts programming
JSP and struts programming
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC Drivers
 
Introduction to J2EE
Introduction to J2EEIntroduction to J2EE
Introduction to J2EE
 

Recently uploaded

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Recently uploaded (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Data structure computer graphs

  • 2. What is a 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. Formal definition 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)
  • 4. Directed vs. undirected graphs • When the edges in a graph have no direction, the graph is called undirected
  • 5. • When the edges in a graph have a direction, the graph is called directed (or digraph) Directed vs. undirected graphs (cont.) E(Graph2) = {(1,3) (3,1) (5,9) (9,11) (5,7) Warning: if the graph is directed, the order of the vertices in each edge is important !!
  • 6. • Trees are special cases of graphs!! Trees vs graphs
  • 7. Graph terminology • 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 • Complete graph: a graph in which every vertex is directly connected to every other vertex 5 is adjacent to 7 7 is adjacent from 5
  • 8. • What is the number of edges in a complete directed graph with N vertices? N * (N-1) Graph terminology (cont.)
  • 9. • What is the number of edges in a complete undirected graph with N vertices? N * (N-1) / 2 Graph terminology (cont.)
  • 10. Graph terminology (cont.) • Multi-graph • Cycle • Loop
  • 11. • Weighted graph: a graph in which each edge carries a value Graph terminology (cont.)
  • 12. 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
  • 14. Graph implementation (cont.) • 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)
  • 16. Adjacency Matrix for Un- Weighted Graphs 1. Adjacency Matrix 2. Matrix for edges 3. Matrix for 2 length paths 4. Matrix for 3 length paths 5. Matrix for n length paths 6. Path Matrix 7. Completely Connected Graph
  • 17. Graph searching • Problem: find a path between two nodes of the graph (e.g., Austin and Washington) • Methods: Depth-First-Search (DFS) or Breadth-First-Search (BFS)
  • 18. Depth-First-Search (DFS) • What is the idea behind DFS? – Travel as far as you can down a path – Back up as little as possible when you reach a "dead end" (i.e., next vertex has been "marked" or there is no next vertex) • DFS can be implemented efficiently using a stack
  • 19. DFS • Algorithm: Starting Node is A 1. Initialize all nodes to ready state(Status=1) 2. Push starting nose A onto Stack and change its status to waiting state (Status=2). 3.Repeat steps 4 & 5 until STACK is empty. 4. Pop Top node N. Process N and change its Status to the processed state (Status=3). 5.Push onto Stack all the neighbors of N that are still in ready state and change their state as waiting state(State=2). 6. Exit.
  • 20. 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 – Back up as far as possible when you reach a "dead end" (i.e., next vertex has been "marked" or there is no next vertex)
  • 21. BFS • Algorithm: Starting Node is A 1. Initialize all nodes to ready state(Status=1) 2. Push starting nose A onto Queue and change its status to waiting state (Status=2). 3.Repeat steps 4 & 5 until Queue is empty. 4. Remove the front node N. Process N and change its Status to the processed state (Status=3). 5.Add to the rear of Queue all the neighbors of N that are still in ready state and change their state to waiting (State=2). 6. Exit.
  • 22. • Examples of Both DFS & BFS.