digraph

# digraph - Directed Graphs Directed Graphs Digraph. Set of...

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

Robert Sedgewick and Kevin Wayne • Copyright © 2006 • http://www.Princeton.EDU/~cos226 Directed Graphs Reference: Chapter 19, Algorithms in Java, 3 rd Edition, Robert Sedgewick 2 Directed Graphs Digraph. Set of objects with oriented pairwise connections. Ex. One-way street, hyperlink. 3 Digraph Applications Digraph Vertex Edge financial stock, currency transaction transportation street intersection, airport highway, airway route scheduling task precedence constraint WordNet synset hypernym Web web page hyperlink game board position legal move telephone person placed call food web species predator-prey relation infectious disease person infection citation journal article citation object graph object pointer inheritance hierarchy class inherits from control flow code block jump 4 Ecological Food Web Food web graph. ! Vertex = species. ! Edge = from prey to predator. http://www.twingroves.district96.k12.il.us/Wetlands/Salamander/SalGraphics/salfoodweb.giff

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

View Full Document
5 Some Digraph Problems Transitive closure. Is there a directed path from v to w ? Strong connectivity. Are all vertices mutually reachable? Topological sort. Can you draw the graph so that all edges point from left to right? PERT/CPM. Given a set of tasks with precedence constraints, what is the earliest that we can complete each task? Shortest path. Given a weighted graph, find best route from s to t ? PageRank. What is the importance of a web page? 6 Digraph Representation Vertex names. ! This lecture: use integers between 0 and V-1 . ! Real world: convert between names and integers with symbol table. Orientation of edge matters. 0 6 4 2 1 5 3 7 12 10 9 11 8 7 Adjacency Matrix Representation Adjacency matrix representation. ! Two-dimensional V ! V boolean array. ! Edge v " w in graph: adj[v][w] = true . 0 6 4 2 1 5 3 7 12 10 9 11 8 0 0 1 1 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 1 0 0 0 0 0 0 0 0 0 5 0 0 0 1 1 0 0 0 0 0 0 0 0 6 0 0 0 0 1 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 1 0 0 0 0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 9 0 0 0 0 0 0 0 0 0 0 1 1 1 10 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 1 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 from to 8 Adjacency List Representation Adjacency list representation. Vertex indexed array of lists. 0: 5 2 1 6 1: 2: 3: 4: 3 5: 4 3 6: 4 7: 8 8: 9: 10 11 12 10: 11: 12 12: 0 6 4 2 1 5 3 7 12 10 9 11 8
9 Adjacency List: Java Implementation Implementation. Same as Graph , but only insert one copy of each edge. public

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This document was uploaded on 06/10/2011.

### Page1 / 10

digraph - Directed Graphs Directed Graphs Digraph. Set of...

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

View Full Document
Ask a homework question - tutors are online