Click or drag to resize
EdgeWeightedGraph Class

The EdgeWeightedGraph class represents an edge-weighted graph of vertices named 0 through V - 1, where each undirected edge is of type and has a real-valued weight. It supports the following two primary operations: add an edge to the graph, iterate over all of the edges incident to a vertex. It also provides methods for returning the number of vertices V and the number of edges E. Parallel edges and self-loops are permitted.

This implementation uses an adjacency-lists representation, which is a vertex-indexed array of @link{Bag} objects. All operations take constant time (in the worst case) except iterating over the edges incident to a given vertex, which takes time proportional to the number of such edges.

Inheritance Hierarchy
SystemObject
  Algs4NetEdgeWeightedGraph

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class EdgeWeightedGraph

The EdgeWeightedGraph type exposes the following members.

Constructors
  NameDescription
Public methodEdgeWeightedGraph(Int32)
Initializes an empty edge-weighted graph with V vertices and 0 edges.
Public methodEdgeWeightedGraph(TextInput)
Initializes an edge-weighted graph from an input stream. The format is the number of vertices V, followed by the number of edges E, followed by E pairs of vertices and edge weights, with each entry separated by whitespace.
Public methodEdgeWeightedGraph(Int32, Int32)
Initializes a random edge-weighted graph with V vertices and E edges.
Top
Properties
  NameDescription
Public propertyE
Returns the number of edges in this edge-weighted graph.
Public propertyV
Returns the number of vertices in this edge-weighted graph.
Top
Methods
  NameDescription
Public methodAddEdge
Adds the undirected edge e to this edge-weighted graph.
Public methodAdj
Returns the edges incident on vertex v.
Public methodDegree
Returns the degree of vertex v.
Public methodEdges
Returns all edges in this edge-weighted graph. To iterate over the edges in this edge-weighted graph, use foreach notation: foreach (Edge e in G.Edges()).
Public methodStatic memberMainTest
Demo test the EdgeWeightedGraph data type.
Public methodToString
Returns a string representation of the edge-weighted graph. This method takes time proportional to E + V.
(Overrides ObjectToString.)
Top
Remarks
For additional documentation, see Section 4.3 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

This class is a C# port from the original Java class EdgeWeightedGraph implementation by Robert Sedgewick and Kevin Wayne.

See Also