SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 22
Graph ,[object Object],[object Object],[object Object]
Adjacency List Representation of a Graph For each  u  є   V , the adjacency list  Adj [ u ] contains all the vertices  v  such that there is an edge ( u ,  v )  є   E .
Adjacency Matrix Representation of a Graph The adjacency-matrix representation of a graph  G  consists of a | V | × | V | matrix  A  = ( aij ) such that a ij =1  if  (i,j)  є  E =o  otherwise
Copyright  © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Copyright  © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Breath-first Search ,[object Object],[object Object]
Breath-first Search ,[object Object]
Breath-first Search ,[object Object],[object Object]
Breath-first Search ,[object Object],[object Object],[object Object]
Copyright  © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Copyright  © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Copyright  © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Depth-first Search The strategy followed by depth-first search is, as its name implies, to search "deeper" in the graph whenever possible.
Depth-first Search The predecessor sub-graph of a depth-first search forms a  depth-first forest  composed of several  depth-first trees . The edges in  Eπ  are called  tree edges .
Depth-first Search ,[object Object],[object Object],[object Object],[object Object]
Depth-first Search Each vertex  v  has two timestamps: the first timestamp  d [ v ] records when  v  is first discovered (and grayed), and the second timestamp  f  [ v ] records when the search finishes examining  v 's adjacency list (and blackens  v ).
Copyright  © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Copyright  © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Copyright  © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Property of Depth-First search An important property of depth-first search is that discovery and finishing times have  parenthesis structure .
Copyright  © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Classification of Edges We can define four edge types in terms of the depth-first forest  Gπ  produced by a depth-first search on  G . 1.  Tree edges  are edges in the depth-first forest  Gπ . Edge ( u ,  v ) is a tree edge if  v  was first discovered by exploring edge ( u ,  v ). 2.  Back edges  are those edges ( u ,  v ) connecting a vertex  u  to an ancestor  v  in a depth first tree. Self-loops, which may occur in directed graphs, are considered to be back edges.
Classification of Edges 3.  Forward edges  are those non-tree edges ( u ,  v ) connecting a vertex  u  to a descendant  v  in a depth-first tree. 4.  Cross edges  are all other edges.
Classification of Edges The DFS algorithm can be modified to classify edges as it encounters them. The key idea is that each edge ( u ,  v ) can be classified by the color of the vertex  v  that is reached when the edge is first explored . 1. WHITE indicates a tree edge, 2. GRAY indicates a back edge, and 3. BLACK indicates a forward or cross edge.
Topological Sort A topological sort of a graph can be viewed as an ordering of its vertices along a horizontal line so that all directed edges go from left to right.
Copyright  © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Copyright  © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Strongly Connected Components A strongly connected component of a directed graph G=(V,E) is a maximal set of vertices  such that for every pair of vertices u and v in C , we have both u ~v and v ~u
Copyright  © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Strongly Connected Components The transpose of a graph G, G T =(V,E T )  is used for finding the strongly connected components of a graph G=(V,E) It is interesting to observe that G and G T  have exactly the same strongly connected components
Copyright  © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Weitere ähnliche Inhalte

Was ist angesagt?

All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithm
Srikrishnan Suresh
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
Shashwat Shriparv
 
Interesting applications of graph theory
Interesting applications of graph theoryInteresting applications of graph theory
Interesting applications of graph theory
Tech_MX
 

Was ist angesagt? (20)

Lecture 05 syntax analysis 2
Lecture 05 syntax analysis 2Lecture 05 syntax analysis 2
Lecture 05 syntax analysis 2
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Optimal binary search tree dynamic programming
Optimal binary search tree   dynamic programmingOptimal binary search tree   dynamic programming
Optimal binary search tree dynamic programming
 
All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithm
 
Chapter 2: Relations
Chapter 2: RelationsChapter 2: Relations
Chapter 2: Relations
 
Little o and little omega
Little o and little omegaLittle o and little omega
Little o and little omega
 
Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)
 
graph.ppt
graph.pptgraph.ppt
graph.ppt
 
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisAnalysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysis
 
Planar graph
Planar graphPlanar graph
Planar graph
 
Biconnected components (13024116056)
Biconnected components (13024116056)Biconnected components (13024116056)
Biconnected components (13024116056)
 
Graphs
GraphsGraphs
Graphs
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
 
Shortest Path in Graph
Shortest Path in GraphShortest Path in Graph
Shortest Path in Graph
 
Strongly Connected Components
Strongly Connected Components Strongly Connected Components
Strongly Connected Components
 
PRIM'S ALGORITHM
PRIM'S ALGORITHMPRIM'S ALGORITHM
PRIM'S ALGORITHM
 
Data structure and algorithm using java
Data structure and algorithm using javaData structure and algorithm using java
Data structure and algorithm using java
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Interesting applications of graph theory
Interesting applications of graph theoryInteresting applications of graph theory
Interesting applications of graph theory
 
Prim's algorithm
Prim's algorithmPrim's algorithm
Prim's algorithm
 

Andere mochten auch

Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
Alizay Khan
 
(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai
Radhika Srinivasan
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Ehtisham Ali
 
Heuristic Search
Heuristic SearchHeuristic Search
Heuristic Search
butest
 

Andere mochten auch (20)

Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in data structure
 
DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
Graphs bfs dfs
Graphs bfs dfsGraphs bfs dfs
Graphs bfs dfs
 
BFS
BFSBFS
BFS
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
 
Breadth first search
Breadth first searchBreadth first search
Breadth first search
 
(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai
 
DFS & BFS Graph
DFS & BFS GraphDFS & BFS Graph
DFS & BFS Graph
 
Depth First Search, Breadth First Search and Best First Search
Depth First Search, Breadth First Search and Best First SearchDepth First Search, Breadth First Search and Best First Search
Depth First Search, Breadth First Search and Best First Search
 
chapter 1
chapter 1chapter 1
chapter 1
 
Bfs dfs
Bfs dfsBfs dfs
Bfs dfs
 
NUMA optimized Parallel Breadth first Search on Multicore Single node System
NUMA optimized Parallel Breadth first Search on Multicore Single node SystemNUMA optimized Parallel Breadth first Search on Multicore Single node System
NUMA optimized Parallel Breadth first Search on Multicore Single node System
 
11. dfs
11. dfs11. dfs
11. dfs
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
2.5 bfs & dfs 02
2.5 bfs & dfs 022.5 bfs & dfs 02
2.5 bfs & dfs 02
 
Prim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning treePrim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning tree
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part II
 
Heuristic Search
Heuristic SearchHeuristic Search
Heuristic Search
 

Ähnlich wie chapter22.ppt

graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docxgraphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
whittemorelucilla
 

Ähnlich wie chapter22.ppt (10)

Breadth first search and depth first search
Breadth first search and  depth first searchBreadth first search and  depth first search
Breadth first search and depth first search
 
chapter23.ppt
chapter23.pptchapter23.ppt
chapter23.ppt
 
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docxgraphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
 
DFS ppt.pdf
DFS ppt.pdfDFS ppt.pdf
DFS ppt.pdf
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
 
Lecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxLecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptx
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structure
 
graph representation.pdf
graph representation.pdfgraph representation.pdf
graph representation.pdf
 
DFS.pdf
DFS.pdfDFS.pdf
DFS.pdf
 

Mehr von Tareq Hasan

08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
Tareq Hasan
 
02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array Pointer
Tareq Hasan
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.ppt
Tareq Hasan
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queue
Tareq Hasan
 

Mehr von Tareq Hasan (20)

Grow Your Career with WordPress
Grow Your Career with WordPressGrow Your Career with WordPress
Grow Your Career with WordPress
 
Caching in WordPress
Caching in WordPressCaching in WordPress
Caching in WordPress
 
How to Submit a plugin to WordPress.org Repository
How to Submit a plugin to WordPress.org RepositoryHow to Submit a plugin to WordPress.org Repository
How to Submit a plugin to WordPress.org Repository
 
Composer - The missing package manager for PHP
Composer - The missing package manager for PHPComposer - The missing package manager for PHP
Composer - The missing package manager for PHP
 
WordPress Theme & Plugin development best practices - phpXperts seminar 2011
WordPress Theme & Plugin development best practices - phpXperts seminar 2011WordPress Theme & Plugin development best practices - phpXperts seminar 2011
WordPress Theme & Plugin development best practices - phpXperts seminar 2011
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
 
02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array Pointer
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.ppt
 
chapter - 6.ppt
chapter - 6.pptchapter - 6.ppt
chapter - 6.ppt
 
Algorithm.ppt
Algorithm.pptAlgorithm.ppt
Algorithm.ppt
 
chapter-8.ppt
chapter-8.pptchapter-8.ppt
chapter-8.ppt
 
chapter24.ppt
chapter24.pptchapter24.ppt
chapter24.ppt
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queue
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Java: Exception
Java: ExceptionJava: Exception
Java: Exception
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
Java: Class Design Examples
Java: Class Design ExamplesJava: Class Design Examples
Java: Class Design Examples
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object References
 

chapter22.ppt

  • 1. Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 22
  • 2.
  • 3. Adjacency List Representation of a Graph For each u є V , the adjacency list Adj [ u ] contains all the vertices v such that there is an edge ( u , v ) є E .
  • 4. Adjacency Matrix Representation of a Graph The adjacency-matrix representation of a graph G consists of a | V | × | V | matrix A = ( aij ) such that a ij =1 if (i,j) є E =o otherwise
  • 5. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 6. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 12. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 13. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 14. Depth-first Search The strategy followed by depth-first search is, as its name implies, to search "deeper" in the graph whenever possible.
  • 15. Depth-first Search The predecessor sub-graph of a depth-first search forms a depth-first forest composed of several depth-first trees . The edges in Eπ are called tree edges .
  • 16.
  • 17. Depth-first Search Each vertex v has two timestamps: the first timestamp d [ v ] records when v is first discovered (and grayed), and the second timestamp f [ v ] records when the search finishes examining v 's adjacency list (and blackens v ).
  • 18. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 19. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 20. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 21. Property of Depth-First search An important property of depth-first search is that discovery and finishing times have parenthesis structure .
  • 22. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 23. Classification of Edges We can define four edge types in terms of the depth-first forest Gπ produced by a depth-first search on G . 1. Tree edges are edges in the depth-first forest Gπ . Edge ( u , v ) is a tree edge if v was first discovered by exploring edge ( u , v ). 2. Back edges are those edges ( u , v ) connecting a vertex u to an ancestor v in a depth first tree. Self-loops, which may occur in directed graphs, are considered to be back edges.
  • 24. Classification of Edges 3. Forward edges are those non-tree edges ( u , v ) connecting a vertex u to a descendant v in a depth-first tree. 4. Cross edges are all other edges.
  • 25. Classification of Edges The DFS algorithm can be modified to classify edges as it encounters them. The key idea is that each edge ( u , v ) can be classified by the color of the vertex v that is reached when the edge is first explored . 1. WHITE indicates a tree edge, 2. GRAY indicates a back edge, and 3. BLACK indicates a forward or cross edge.
  • 26. Topological Sort A topological sort of a graph can be viewed as an ordering of its vertices along a horizontal line so that all directed edges go from left to right.
  • 27. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 28. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 29. Strongly Connected Components A strongly connected component of a directed graph G=(V,E) is a maximal set of vertices such that for every pair of vertices u and v in C , we have both u ~v and v ~u
  • 30. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 31. Strongly Connected Components The transpose of a graph G, G T =(V,E T ) is used for finding the strongly connected components of a graph G=(V,E) It is interesting to observe that G and G T have exactly the same strongly connected components
  • 32. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.