This preview shows pages 1–4. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Graphs Defn: An undirected graph is a pair ( V, E ) , where V is a finite set of vertices ; and E is a set of edges , which are 2element subsets of V . Defn: A directed graph is a pair ( V, E ) , where V is a finite set of vertices ; and E is a set of edges , which are ordered pairs of distinct elements of V . 1 The Data Type Edge Representation Variables: source : the vertex at which the edge begins dest : the vertex at which the edge ends data : information associated with the edge All variables are readable. 2 Precondition: n is a Nat . Postcondition: Constructs a Graph with vertices , . . . , n 1 and no edges. Graph ( n ) Precondition: true . Postcondition: Returns the number of vertices. Graph.Size () Precondition: i and j are Nat s less than the number of vertices, i negationslash = j , x refers to a non nil item. Postcondition: Associates x with the edge ( i, j ) , adding this edge if necessary. Graph.Put ( i, j, x ) 3 Precondition: i and j are Nat s less than the number of vertices. Postcondition: Returns the data item associated with edge ( i, j ) , or nil if ( i, j ) is not in the graph. Graph.Get ( i, j ) Precondition: i is a Nat less than the number of vertices. Postcondition: Returns a ConsList of Edge s representing the edges proceeding from vertex i , where an edge ( i, j ) with data x is represented by an Edge with source = i , dest = j , and data = x . Graph.AllFrom ( i ) 4 Universal Sink Detection Defn: Let G = ( V, E ) be a directed graph. A universal sink in G is a vertex u V such that for every v V \{ u } : ( u, v ) negationslash E ; and ( v, u ) E . Input: A directed graph G . Output: A universal sink in G , or 1 if no universal sink exists. 5 Variation: Restrict the input to nonempty graphs, and return an arbitrary vertex if no universal sink exists. If G has only one vertex, we can return it....
View
Full
Document
 Spring '09
 Howell

Click to edit the document details