public interface Graph
Note that this particular interface explicitly refers to vertices by a consecutive set of integral vertex IDs, from 0 to N-1 (where N is the number of vertices), and conceives of edges only in terms of their endpoints. This is the canonical conception of a graph for standard graph algorithms, but lacks common features for modeling, e.g., a road network.
To represent metadata like vertex labels, it is recommended that the user maintain their own dictionaries mapping between vertex IDs (or pairs thereof, for edges) and the desired values.
Any method that takes one or more vertex IDs as arguments may throw an IndexOutOfBoundsException if any input ID is out of bounds.
Modifier and Type | Method and Description |
---|---|
int |
addVertex()
Adds a new vertex.
|
void |
clear()
Removes all vertices and edges from the graph.
|
int |
getDegree(int v)
Returns the out-degree of the specified vertex.
|
int |
getInDegree(int v)
Returns the in-degree of the specified vertex.
|
java.lang.Iterable<java.lang.Integer> |
getNeighbors(int v)
Returns an iterable object that allows iteration over the neighbors of
the specified vertex.
|
boolean |
hasEdge(int begin,
int end)
Returns whether an edge exists between two vertices.
|
boolean |
isDirected()
Returns true if the graph is directed.
|
boolean |
isEmpty()
Returns true if there are no vertices in the graph.
|
int |
numEdges()
Returns the number of edges in the graph.
|
int |
numVerts()
Returns the number of vertices in the graph.
|
int addVertex()
boolean hasEdge(int begin, int end)
int getDegree(int v)
int getInDegree(int v)
java.lang.Iterable<java.lang.Integer> getNeighbors(int v)
int numVerts()
int numEdges()
boolean isDirected()
boolean isEmpty()
void clear()