lec22 - (* A signature for module type WGRAPH type graph (*...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
(* A signature for directed graphs.*) module type WGRAPH = sig type graph (* A directed graph consisting of a set of vertices * V and directed edges E with integer weights. *) type vertex (* A vertex, or node, of the graph *) type edge (* A edge of the graph *) (* create an empty graph *) val create: unit -> graph (* return the id of the specified vertex *) val vertex_id: vertex -> int (* compare two vertices, returning 0 if their id's are equal, -1 if the first has a smaller id and +1 if first has a larger id. Suitable for comparators in sets and maps. *) val compare: vertex -> vertex -> int (* For an edge return (src,dst,w) where src is the source vertex of * the edge, dst is the destination vertex, and w is the edge * weight. *) val edge_info: edge -> vertex * vertex * int (* True if the given graph is empty (has no vertices). Run time O(1). *) val is_empty: graph -> bool (* A list of all vertices in the graph, without duplicates, in the order * they were added. * Run time: O(|V|). *) val vertices: graph -> vertex list (* A list of all vertices in the graph, without duplicates, in the order * they were added. * Run time: O(1). *) val num_vertices: graph -> int (* A list of all edges in the graph, without duplicates. *Run time: O(|V|+|E|). *) val edges: graph -> edge list (* A list of the edges leaving the vertex v. * Run time: linear in the length of the result. *) val outgoing: vertex -> edge list (* A list of the edges coming in to the vertex v, where each edge is * reversed to go from v back to the other vertex. Run time: linear * in the length of the result. *) val incoming_rev: vertex -> edge list (* The number of incoming edges for the specified vertex. Run time: O(1). *) val in_degree: vertex -> int (* The number of outgoing edges for the specified vertex. Run time: O(1). *) val out_degree: vertex -> int (* Effect: adds a new singleton vertex (a vertex with no incident edges) to the specified graph, and returns that vertex. Run time: O(1).*) val add_vertex: graph -> vertex
Background image of page 1

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

View Full DocumentRight Arrow Icon
(* Effect: removes specified vertex from the specified graph, and * all edges that are incident on that vertex, i.e., all edges that * have the vertex as a source or destination. Run time: O(|E|).*) val remove_vertex: graph -> vertex -> unit (* Effect: add_edge(src,dst,w) adds an edge from src vertex to dst * vertex, with weight w. Run time: O(1).*) val add_edge: vertex * vertex * int -> unit (* Effect: remove_edge(src,dst) removes the edge from src vertex to * dst vertex, has no effect if the edge does not exist. Run time: O(|E|).*) val remove_edge: vertex * vertex -> unit (* Creates and returns a copy of the graph. Run time: O(|V|+|E|). *) val copy: graph -> graph end (* A representation of directed graphs with integer weighted edges, in * terms of adjacency lists of vertices, explicitly representing both * the outgoing edge list and the incoming edge at each vertex.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/25/2009 for the course PHYS 2214 at Cornell University (Engineering School).

Page1 / 7

lec22 - (* A signature for module type WGRAPH type graph (*...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online