Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 2300 Data Structures & Algorithms March 30, 2007 Chapter 9. Graph Algorithms.

Similar presentations


Presentation on theme: "CSC 2300 Data Structures & Algorithms March 30, 2007 Chapter 9. Graph Algorithms."— Presentation transcript:

1 CSC 2300 Data Structures & Algorithms March 30, 2007 Chapter 9. Graph Algorithms

2 Today – Graphs Graphs –  Overview  Definitions  Representation Topological Sort

3 Graphs – Overview

4 Definitions

5 More Definitions

6 Conventions

7 Directed Graph – Example

8 Graph Representations 1. Adjacency matrix 2. Adjacency list

9 Adjacency Matrix What does adjacency matrix look like? There are |E| edges and |V| vertices. How much space is used?

10 Adjacency List – Example There are |E| edges and |V| vertices. How much space is used?

11 Two More Examples

12 Graph Algorithms Overview

13 Topological Sort

14 Example – Course Prerequisites

15 Example – Indegrees What are the indegrees of the seven vertices? Is there a vertex with indegree = 0? Is it possible that there exists no vertex with indegree = 0?

16 Topological Sort Scan the array of vertices to look for a vertex with indegree 0 that has not been assigned a topological number. There are |E| edges and |V| vertices. What is the running time of this algorithm? Is it possible to do better?

17 Improved Topological Sort Why always scan through all the vertices? Only a few vertices have their indegrees updated during each iteration. We keep all (unassigned) vertices of indegree 0 in a queue. When a vertex v is removed from the queue, all vertices adjacent to v will have their indegrees decremented. A vertex is placed in the queue if its indegree has fallen to 0. There are |E| edges and |V| vertices. What is the running time of this new approach?

18 Improved Topological Sort

19 Topological Sort – Example How many iterations? Big Oh of what?


Download ppt "CSC 2300 Data Structures & Algorithms March 30, 2007 Chapter 9. Graph Algorithms."

Similar presentations


Ads by Google