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?

Application Of Graph Data Structure
Application Of Graph Data StructureApplication Of Graph Data Structure
Application Of Graph Data StructureGaurang Dobariya
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtrackingmandlapure
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptxSyed Zaid Irshad
 
Red black tree
Red black treeRed black tree
Red black treeRajendran
 
Ch11 file system implementation
Ch11 file system implementationCh11 file system implementation
Ch11 file system implementationAbdullah Al Shiam
 
Datapath Design of Computer Architecture
Datapath Design of Computer ArchitectureDatapath Design of Computer Architecture
Datapath Design of Computer ArchitectureAbu Zaman
 
Computer architecture page replacement algorithms
Computer architecture page replacement algorithmsComputer architecture page replacement algorithms
Computer architecture page replacement algorithmsMazin Alwaaly
 
Page replacement
Page replacementPage replacement
Page replacementsashi799
 
3.8 quick sort
3.8 quick sort3.8 quick sort
3.8 quick sortKrish_ver2
 
Communication costs in parallel machines
Communication costs in parallel machinesCommunication costs in parallel machines
Communication costs in parallel machinesSyed Zaid Irshad
 

Was ist angesagt? (20)

Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
Disjoint sets union, find
Disjoint sets  union, findDisjoint sets  union, find
Disjoint sets union, find
 
Application Of Graph Data Structure
Application Of Graph Data StructureApplication Of Graph Data Structure
Application Of Graph Data Structure
 
Binary tree
Binary  treeBinary  tree
Binary tree
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtracking
 
Page Replacement
Page ReplacementPage Replacement
Page Replacement
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptx
 
Red black tree
Red black treeRed black tree
Red black tree
 
Computer Science-Data Structures :Abstract DataType (ADT)
Computer Science-Data Structures :Abstract DataType (ADT)Computer Science-Data Structures :Abstract DataType (ADT)
Computer Science-Data Structures :Abstract DataType (ADT)
 
Ch11 file system implementation
Ch11 file system implementationCh11 file system implementation
Ch11 file system implementation
 
pipelining
pipeliningpipelining
pipelining
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Datapath Design of Computer Architecture
Datapath Design of Computer ArchitectureDatapath Design of Computer Architecture
Datapath Design of Computer Architecture
 
I/O Buffering
I/O BufferingI/O Buffering
I/O Buffering
 
Computer architecture page replacement algorithms
Computer architecture page replacement algorithmsComputer architecture page replacement algorithms
Computer architecture page replacement algorithms
 
Page replacement
Page replacementPage replacement
Page replacement
 
Deadlock
DeadlockDeadlock
Deadlock
 
3.8 quick sort
3.8 quick sort3.8 quick sort
3.8 quick sort
 
Trees
TreesTrees
Trees
 
Communication costs in parallel machines
Communication costs in parallel machinesCommunication costs in parallel machines
Communication costs in parallel machines
 

Andere mochten auch

Dfs presentation
Dfs presentationDfs presentation
Dfs presentationAlizay Khan
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in data structure Ankit Kumar Singh
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationAmrinder Arora
 
(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 aiRadhika Srinivasan
 
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 SearchAdri Jovin
 
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 SystemMohammad Tahsin Alshalabi
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsEhtisham Ali
 
2.5 bfs & dfs 02
2.5 bfs & dfs 022.5 bfs & dfs 02
2.5 bfs & dfs 02Krish_ver2
 
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 treeoneous
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part IIAmrinder Arora
 
Heuristic Search
Heuristic SearchHeuristic Search
Heuristic Searchbutest
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSGayathri Gaayu
 

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
 
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
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 

Ähnlich wie Intro Algorithms Chapter 22 Graph Representations BFS DFS SCC

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 searchHossain Md Shakhawat
 
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.docxwhittemorelucilla
 
DFS ppt.pdf
DFS ppt.pdfDFS ppt.pdf
DFS ppt.pdfRajkk5
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx pptDhruvilSTATUS
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]DEEPIKA T
 
Lecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxLecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxking779879
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structureIkhlas Rahman
 
graph representation.pdf
graph representation.pdfgraph representation.pdf
graph representation.pdfamitbhachne
 

Ähnlich wie Intro Algorithms Chapter 22 Graph Representations BFS DFS SCC (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

Grow Your Career with WordPress
Grow Your Career with WordPressGrow Your Career with WordPress
Grow Your Career with WordPressTareq Hasan
 
Caching in WordPress
Caching in WordPressCaching in WordPress
Caching in WordPressTareq Hasan
 
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 RepositoryTareq Hasan
 
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 PHPTareq Hasan
 
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 2011Tareq Hasan
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.pptTareq Hasan
 
02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array PointerTareq Hasan
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.pptTareq Hasan
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queueTareq Hasan
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-SortTareq Hasan
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: InheritanceTareq Hasan
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to ArraysTareq Hasan
 
Java: Class Design Examples
Java: Class Design ExamplesJava: Class Design Examples
Java: Class Design ExamplesTareq Hasan
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object ReferencesTareq 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
 

Intro Algorithms Chapter 22 Graph Representations BFS DFS SCC

  • 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.