Click or drag to resize
Graph Class

The Graph class represents an undirected graph of vertices named 0 through V - 1. It supports the following two primary operations: add an edge to the graph, iterate over all of the vertices adjacent 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 objects. All operations take constant time (in the worst case) except iterating over the vertices adjacent to a given vertex, which takes time proportional to the number of such vertices.

Inheritance Hierarchy
SystemObject
  Algs4NetGraph

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

The Graph type exposes the following members.

Constructors
  NameDescription
Public methodGraph(Int32)
Initializes an empty graph with V vertices and 0 edges. param V the number of vertices
Public methodGraph(Graph)
Initializes a new graph that is a deep copy of G.
Public methodGraph(TextInput)
Initializes a graph from an initialized TextInput stream The format is the number of vertices V, followed by the number of edges E, followed by E pairs of vertices, with each entry separated by whitespace.
Top
Properties
  NameDescription
Public propertyE
Returns the number of edges in this graph.
Public propertyV
Returns the number of vertices in this graph.
Top
Methods
  NameDescription
Public methodAddEdge(Edge)
Adds the undirected edge to this graph.
Public methodAddEdge(Int32, Int32)
Adds the undirected edge v-w to this graph.
Public methodAdj
Returns the vertices adjacent to vertex v.
Public methodDegree
Returns the degree of vertex v.
Public methodStatic memberMainTest
Demo test the Graph data type.
Public methodToString
Returns a string representation of this graph.
(Overrides ObjectToString.)
Top
Remarks

For additional documentation, see Section 4.1 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

This class is a C# port from the original Java class Graph implementation by the respective authors.

See Also