Graphs

Graphs ,[object Object],[object Object],[object Object],[object Object],D E A C F B Vertex Edge Vertices can be considered “sites” or locations. Edges represent connections.
Applications Air flight system ,[object Object],[object Object],[object Object],[object Object],[object Object]
Another application ,[object Object],[object Object],[object Object],[object Object],[object Object]
Definition ,[object Object],[object Object],{c,f} {a,c} {a,b} {b,d} {c,d} {e,f} {b,e}
Terminology ,[object Object],[object Object],[object Object],[object Object],*Later, we will talk about “directed graphs”, where edges have direction.  This means that {v 1 ,v 2 } ≠ {v 2 ,v 1 } .  Directed graphs are drawn with arrows (called arcs) between edges.  A B This means {A,B} only, not {B,A}
Graph Representation ,[object Object],[object Object],[object Object],[object Object],[object Object]
Adjacency Matrix ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Adjacency list ,[object Object],[object Object],[object Object]
Examples 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 0 1 2 0 1 0 0 1 0 0 0 1 0 3 0 1 0 0 1 1 0 0 0 0 4 0 0 1 1 0 0 0 0 0 0 5 0 0 0 1 0 0 1 0 0 0 6 0 0 0 0 0 1 0 1 0 0 7 0 1 0 0 0 0 1 0 0 0 8 1 0 1 0 0 0 0 0 0 1 9 0 1 0 0 0 0 0 0 1 0
Examples 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 2 3 7 9 8 1 4 8 1 4 5 2 3 3 6 5 7 1 6 0 2 9 1 8
Storage of adjacency list ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Adjacency Lists vs. Matrix ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Path between vertices ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Types of paths ,[object Object],[object Object],[object Object],[object Object]
Examples ,[object Object],[object Object],[object Object],[object Object],[object Object],Are these paths? Any cycles? What is the path’s length?
Graph Traversal ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
BFS and Shortest Path Problem ,[object Object],[object Object],Consider s=vertex 1 Nodes at distance 1? 2, 3, 7, 9 Example Nodes at distance 2? 8, 6, 5, 4 Nodes at distance 3? 0 2 4 3 5 1 7 6 9 8 0 1 1 1 1 2 2 2 2 s
BSF algorithm Why use queue? Need FIFO
Example Adjacency List source Visited Table (T/F) Q =  {  } Initialize visited table (all False) Initialize Q to be empty 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 F F F F F F F F F F
Example Adjacency List source Visited Table (T/F) Q =  {  2  } Flag that 2 has  been visited. Place source 2 on the queue. 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 F F T F F F F F F F
Example Adjacency List source Visited Table (T/F) Q =  {2} ->  {  8, 1, 4 } Mark neighbors as visited. Dequeue 2.  Place all  unvisited  neighbors of 2 on the queue Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 F T T F T F F F T F
Example Adjacency List source Visited Table (T/F) Q =  {  8, 1, 4 } -> { 1, 4, 0, 9 }  Mark new visited Neighbors. Dequeue 8.  -- Place all unvisited neighbors of 8 on the queue. -- Notice that 2 is not placed on the queue again, it has been visited! Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T F T F F F T T
Example Adjacency List source Visited Table (T/F) Q =  {  1, 4, 0, 9 } -> { 4, 0, 9, 3, 7 }  Mark new visited Neighbors. Dequeue 1.  -- Place all unvisited neighbors of 1 on the queue. -- Only nodes 3 and 7 haven’t been visited yet. Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F T T T
Example Adjacency List source Visited Table (T/F) Q =  { 4, 0, 9, 3, 7 } -> { 0, 9, 3, 7 }  Dequeue 4.  -- 4 has no unvisited neighbors! Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F T T T
Example Adjacency List source Visited Table (T/F) Q =  { 0, 9, 3, 7 } -> { 9, 3, 7 }  Dequeue 0.  -- 0 has no unvisited neighbors! Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F T T T
Example Adjacency List source Visited Table (T/F) Q =  { 9, 3, 7 } -> { 3, 7 }  Dequeue 9.  -- 9 has no unvisited neighbors! Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F T T T
Example Adjacency List source Visited Table (T/F) Q =  { 3, 7 } -> { 7, 5 }  Dequeue 3.  -- place neighbor 5 on the queue. Neighbors Mark new visited Vertex 5. 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T F T T T
Example Adjacency List source Visited Table (T/F) Q =  { 7, 5 } -> { 5, 6 }  Dequeue 7.  -- place neighbor 6 on the queue. Neighbors Mark new visited Vertex 6. 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T T T T T
Example Adjacency List source Visited Table (T/F) Q =  { 5, 6} -> { 6 }  Dequeue 5.  -- no unvisited neighbors of 5. Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T T T T T
Example Adjacency List source Visited Table (T/F) Q =  { 6 } -> {  }  Dequeue 6.  -- no unvisited neighbors of 6. Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T T T T T
Example Adjacency List source Visited Table (T/F) Q =  {  }  STOP!!!  Q is empty!!! What did we discover? Look at “visited” tables. There exists a path from source vertex 2 to all vertices in the graph. 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T T T T T
Time Complexity of BFS (Using adjacency list) ,[object Object],[object Object],Each vertex will enter Q at most once. Each iteration takes time proportional to deg(v) + 1  (the number 1 is to include the case where deg(v) = 0). O(n + m)
Running time ,[object Object],[object Object],[object Object],O(  Σ vertex  v  (deg(v)  +  1) )  =  O(n+m) Σ vertex  v  deg(v)   =   2m
1 de 33

Recomendados

Graphs - Discrete Math por
Graphs - Discrete MathGraphs - Discrete Math
Graphs - Discrete MathSikder Tahsin Al-Amin
13.7K vistas18 diapositivas
Graph theory por
Graph theoryGraph theory
Graph theoryAparnaKumari31
2K vistas13 diapositivas
Graph theory presentation por
Graph theory presentationGraph theory presentation
Graph theory presentationAliul Kadir Akib
24.7K vistas24 diapositivas
Graph Theory por
Graph TheoryGraph Theory
Graph TheoryEhsan Hamzei
4.1K vistas14 diapositivas
Graph theory por
Graph theoryGraph theory
Graph theoryThirunavukarasu Mani
9.9K vistas139 diapositivas
Graphs por
GraphsGraphs
Graphsrajeshree nanaware
136 vistas8 diapositivas

Más contenido relacionado

La actualidad más candente

Graph Theory Introduction por
Graph Theory IntroductionGraph Theory Introduction
Graph Theory IntroductionMANISH T I
1.9K vistas18 diapositivas
Graph terminologies & special type graphs por
Graph terminologies & special type graphsGraph terminologies & special type graphs
Graph terminologies & special type graphsNabeel Ahsen
6.4K vistas34 diapositivas
Basics on Graph Theory por
Basics on Graph TheoryBasics on Graph Theory
Basics on Graph TheoryGuillaume Guérard
1.3K vistas37 diapositivas
graph theory por
graph theory graph theory
graph theory ganith2k13
14.5K vistas93 diapositivas
Graph theory por
Graph theoryGraph theory
Graph theoryGaditek
1.4K vistas42 diapositivas
graph theory por
graph theorygraph theory
graph theoryShashank Singh
2.2K vistas52 diapositivas

La actualidad más candente(16)

Destacado

Vertex Edge Graphs por
Vertex Edge GraphsVertex Edge Graphs
Vertex Edge Graphsmrwilliams
1K vistas13 diapositivas
Vertex edge graphs por
Vertex edge graphsVertex edge graphs
Vertex edge graphsemteacher
4.4K vistas19 diapositivas
Test cases por
Test casesTest cases
Test casesNataly Chill
2.7K vistas11 diapositivas
Test Case Management with MTM 2013 por
Test Case Management with MTM 2013Test Case Management with MTM 2013
Test Case Management with MTM 2013Raluca Suditu
6.1K vistas98 diapositivas
Software Verification, Validation and Testing por
Software Verification, Validation and TestingSoftware Verification, Validation and Testing
Software Verification, Validation and TestingDr Sukhpal Singh Gill
1.5K vistas33 diapositivas
Test design techniques: Structured and Experienced-based techniques por
Test design techniques: Structured and Experienced-based techniquesTest design techniques: Structured and Experienced-based techniques
Test design techniques: Structured and Experienced-based techniquesKhuong Nguyen
12.7K vistas55 diapositivas

Destacado(14)

Vertex Edge Graphs por mrwilliams
Vertex Edge GraphsVertex Edge Graphs
Vertex Edge Graphs
mrwilliams1K vistas
Vertex edge graphs por emteacher
Vertex edge graphsVertex edge graphs
Vertex edge graphs
emteacher4.4K vistas
Test Case Management with MTM 2013 por Raluca Suditu
Test Case Management with MTM 2013Test Case Management with MTM 2013
Test Case Management with MTM 2013
Raluca Suditu6.1K vistas
Test design techniques: Structured and Experienced-based techniques por Khuong Nguyen
Test design techniques: Structured and Experienced-based techniquesTest design techniques: Structured and Experienced-based techniques
Test design techniques: Structured and Experienced-based techniques
Khuong Nguyen12.7K vistas
Data structure computer graphs por Kumar
Data structure computer graphsData structure computer graphs
Data structure computer graphs
Kumar 4.4K vistas
Graph data structure por Tech_MX
Graph data structureGraph data structure
Graph data structure
Tech_MX14.1K vistas
Graph representation por Tech_MX
Graph representationGraph representation
Graph representation
Tech_MX37.2K vistas
The Graph Traversal Programming Pattern por Marko Rodriguez
The Graph Traversal Programming PatternThe Graph Traversal Programming Pattern
The Graph Traversal Programming Pattern
Marko Rodriguez56.3K vistas

Similar a Graphs

Week12 graph por
Week12   graph Week12   graph
Week12 graph IIUM
112 vistas65 diapositivas
Graps 2 por
Graps 2Graps 2
Graps 2Saurabh Mishra
334 vistas42 diapositivas
Breadth first search por
Breadth first searchBreadth first search
Breadth first searchSazzad Hossain
333 vistas41 diapositivas
Lecture 5b graphs and hashing por
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashingVictor Palmar
1.2K vistas56 diapositivas
Graphs por
GraphsGraphs
GraphsKomalPaliwal3
66 vistas44 diapositivas
Graph por
GraphGraph
GraphMudassar Mushtaq
412 vistas52 diapositivas

Similar a Graphs(20)

Week12 graph por IIUM
Week12   graph Week12   graph
Week12 graph
IIUM112 vistas
Lecture 5b graphs and hashing por Victor Palmar
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
Victor Palmar1.2K vistas
Temporal graph por Vinay Sarda
Temporal graphTemporal graph
Temporal graph
Vinay Sarda4.7K vistas
lecture 17 por sajinsc
lecture 17lecture 17
lecture 17
sajinsc588 vistas
graph.pptx por hijigaf
graph.pptxgraph.pptx
graph.pptx
hijigaf14 vistas
Topological sort por jabishah
Topological sortTopological sort
Topological sort
jabishah80 vistas

Más de Saurabh Mishra

Sorting2 por
Sorting2Sorting2
Sorting2Saurabh Mishra
600 vistas80 diapositivas
Sorting por
SortingSorting
SortingSaurabh Mishra
884 vistas40 diapositivas
Searching por
SearchingSearching
SearchingSaurabh Mishra
584 vistas14 diapositivas
Presentation1 por
Presentation1Presentation1
Presentation1Saurabh Mishra
369 vistas37 diapositivas
Data structures por
Data structuresData structures
Data structuresSaurabh Mishra
20.2K vistas254 diapositivas
Trees por
TreesTrees
TreesSaurabh Mishra
616 vistas53 diapositivas

Último

Attacking IoT Devices from a Web Perspective - Linux Day por
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day Simone Onofri
15 vistas68 diapositivas
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors por
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensorssugiuralab
19 vistas15 diapositivas
virtual reality.pptx por
virtual reality.pptxvirtual reality.pptx
virtual reality.pptxG036GaikwadSnehal
11 vistas15 diapositivas
ChatGPT and AI for Web Developers por
ChatGPT and AI for Web DevelopersChatGPT and AI for Web Developers
ChatGPT and AI for Web DevelopersMaximiliano Firtman
187 vistas82 diapositivas
The details of description: Techniques, tips, and tangents on alternative tex... por
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...BookNet Canada
126 vistas24 diapositivas
Transcript: The Details of Description Techniques tips and tangents on altern... por
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...BookNet Canada
135 vistas15 diapositivas

Último(20)

Attacking IoT Devices from a Web Perspective - Linux Day por Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri15 vistas
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors por sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab19 vistas
The details of description: Techniques, tips, and tangents on alternative tex... por BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada126 vistas
Transcript: The Details of Description Techniques tips and tangents on altern... por BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada135 vistas
Report 2030 Digital Decade por Massimo Talia
Report 2030 Digital DecadeReport 2030 Digital Decade
Report 2030 Digital Decade
Massimo Talia15 vistas
STPI OctaNE CoE Brochure.pdf por madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb13 vistas
DALI Basics Course 2023 por Ivory Egg
DALI Basics Course  2023DALI Basics Course  2023
DALI Basics Course 2023
Ivory Egg16 vistas
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... por James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson66 vistas
Spesifikasi Lengkap ASUS Vivobook Go 14 por Dot Semarang
Spesifikasi Lengkap ASUS Vivobook Go 14Spesifikasi Lengkap ASUS Vivobook Go 14
Spesifikasi Lengkap ASUS Vivobook Go 14
Dot Semarang37 vistas
Data-centric AI and the convergence of data and model engineering: opportunit... por Paolo Missier
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...
Paolo Missier39 vistas
Igniting Next Level Productivity with AI-Infused Data Integration Workflows por Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software257 vistas
Perth MeetUp November 2023 por Michael Price
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023
Michael Price19 vistas
Unit 1_Lecture 2_Physical Design of IoT.pdf por StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec12 vistas

Graphs

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. Examples 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 0 1 2 0 1 0 0 1 0 0 0 1 0 3 0 1 0 0 1 1 0 0 0 0 4 0 0 1 1 0 0 0 0 0 0 5 0 0 0 1 0 0 1 0 0 0 6 0 0 0 0 0 1 0 1 0 0 7 0 1 0 0 0 0 1 0 0 0 8 1 0 1 0 0 0 0 0 0 1 9 0 1 0 0 0 0 0 0 1 0
  • 10. Examples 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 2 3 7 9 8 1 4 8 1 4 5 2 3 3 6 5 7 1 6 0 2 9 1 8
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18. BSF algorithm Why use queue? Need FIFO
  • 19. Example Adjacency List source Visited Table (T/F) Q = { } Initialize visited table (all False) Initialize Q to be empty 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 F F F F F F F F F F
  • 20. Example Adjacency List source Visited Table (T/F) Q = { 2 } Flag that 2 has been visited. Place source 2 on the queue. 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 F F T F F F F F F F
  • 21. Example Adjacency List source Visited Table (T/F) Q = {2} -> { 8, 1, 4 } Mark neighbors as visited. Dequeue 2. Place all unvisited neighbors of 2 on the queue Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 F T T F T F F F T F
  • 22. Example Adjacency List source Visited Table (T/F) Q = { 8, 1, 4 } -> { 1, 4, 0, 9 } Mark new visited Neighbors. Dequeue 8. -- Place all unvisited neighbors of 8 on the queue. -- Notice that 2 is not placed on the queue again, it has been visited! Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T F T F F F T T
  • 23. Example Adjacency List source Visited Table (T/F) Q = { 1, 4, 0, 9 } -> { 4, 0, 9, 3, 7 } Mark new visited Neighbors. Dequeue 1. -- Place all unvisited neighbors of 1 on the queue. -- Only nodes 3 and 7 haven’t been visited yet. Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F T T T
  • 24. Example Adjacency List source Visited Table (T/F) Q = { 4, 0, 9, 3, 7 } -> { 0, 9, 3, 7 } Dequeue 4. -- 4 has no unvisited neighbors! Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F T T T
  • 25. Example Adjacency List source Visited Table (T/F) Q = { 0, 9, 3, 7 } -> { 9, 3, 7 } Dequeue 0. -- 0 has no unvisited neighbors! Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F T T T
  • 26. Example Adjacency List source Visited Table (T/F) Q = { 9, 3, 7 } -> { 3, 7 } Dequeue 9. -- 9 has no unvisited neighbors! Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F T T T
  • 27. Example Adjacency List source Visited Table (T/F) Q = { 3, 7 } -> { 7, 5 } Dequeue 3. -- place neighbor 5 on the queue. Neighbors Mark new visited Vertex 5. 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T F T T T
  • 28. Example Adjacency List source Visited Table (T/F) Q = { 7, 5 } -> { 5, 6 } Dequeue 7. -- place neighbor 6 on the queue. Neighbors Mark new visited Vertex 6. 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T T T T T
  • 29. Example Adjacency List source Visited Table (T/F) Q = { 5, 6} -> { 6 } Dequeue 5. -- no unvisited neighbors of 5. Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T T T T T
  • 30. Example Adjacency List source Visited Table (T/F) Q = { 6 } -> { } Dequeue 6. -- no unvisited neighbors of 6. Neighbors 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T T T T T
  • 31. Example Adjacency List source Visited Table (T/F) Q = { } STOP!!! Q is empty!!! What did we discover? Look at “visited” tables. There exists a path from source vertex 2 to all vertices in the graph. 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T T T T T
  • 32.
  • 33.