{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# 13Graphs - Chapter 13 Graphs The graph ADT while relatively...

This preview shows pages 1–7. Sign up to view the full content.

CS 240  Chapter 13 - Graphs 1Page 1 Chapter 13 Graphs The graph ADT, while relatively unstructured, provides a platform for solving  some of the most sophisticated problems in computer science. ü  Graph Abstract Data Types ü  Spanning Tree ü  Topological Sort ü  Depth-First Search ü  Minimum Path ü  Maximum Flow

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS 240  Chapter 13 - Graphs 2Page 2 Graph Definition A graph G = (V, E) consists of a set of vertices, V, and a set of edges, E,  each of which is a pair of vertices.  If the edges are ordered  pairs of  vertices, then the graph is directed. Undirected, unweighted, unconnected, loopless graph (length of longest simple path: 2) Directed, unweighted, acyclic, weakly connected, loopless graph (length of longest simple path: 6) Directed, unweighted, cyclic, strongly connected, loopless graph (length of longest simple cycle: 7) Undirected, unweighted, connected graph, with loops (length of longest simple path: 4) Directed, weighted, cyclic, weakly connected, loopless graph (weight of longest simple cycle: 27) 3 4 2 4 2 3 5 6 3 6 5
CS 240  Chapter 13 - Graphs 3Page 3 Graph Representations Adjacency Matrix: A B D H E G F C A B C D E F G H A B C D E F G H 1 1 0 0 0 0 1 0 1 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0 1 0 0 0 0 0 0 1 0 A B D H E G F C A B C D E F G H A B C D E F G H 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 A B D H E G F C 3 4 2 4 2 3 5 6 3 6 5 A B C D E F G H A B C D E F G H 4 4 4 4 4 4 2 4 3 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4 6 4 4 4 4 4 4 4 4 6 4 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 4 4 4 5 4 4 4 4 3 4 4 4 The Problem: Most graphs are sparse (i.e., most vertex pairs are not  edges), so  the memory requirement is excessive (i.e.,  V+2).

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS 240  Chapter 13 - Graphs 4Page 4 Adjacency List: A B C D E F G H A A B B E G A G B C G E G D F H A B D H E G F C A B C D E F G H B B 3 H G 6 2 4 C A 3 5 3 5 4 2 D E G G 6 E A B D H E G F C 3 4 2 4 2 3 5 6 3 6 5 A B C D E F G H B E B G C A E D F G D H A B D H E G F C
CS 240  Chapter 13 - Graphs 5Page 5 Topological Sort A topological sort of an acyclic directed graph orders the vertices so that if there is a  path from vertex u to vertex v, then vertex v appears after vertex u in the  ordering. One topological sort of the course  prerequisite graph at right: MATH 120, MATH 150, CS 140, MATH 223, CS 150, CS 240, MATH 152, CS 275, CS 312, CS 321, CS 250, CS 314, CS 425, ECE 382, CS 434, ECE 483, CS 330, STAT 380, CS 407, CS 423, CS 416, CS 325, CS 438, CS 454, CS 447, CS 499, CS 482, CS 456, CS 444, ECE 481, ECE  482 MAT H 120 CS 140 CS 150 MAT H 152 CS 240 CS 275 MAT H 223 CS 250 CS 407 STAT 380 CS 438 CS 454 CS 456 CS 325 CS 499 CS 434 CS 312 CS 482 CS 330 CS 423 CS 416 CS 444 CS 447 MAT H 150 CS 314 CS 425 CS 321 ECE 483 ECE 382 ECE 481 ECE 482

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS 240  Chapter 13 - Graphs 6Page 6 Topological Sort Algorithm Place all indegree-zero vertices in a list.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 20

13Graphs - Chapter 13 Graphs The graph ADT while relatively...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online