|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ConnectedComponents
A ConnectedComponents
maintains information about
the connected components of an undirected graph. As such it is
essentially the same as a general purpose union-find algorithm,
with the added feature that it can return the least element in
a set (i.e., in a connected component).
The algorithm uses a union by size method combined with path compression.
It supports the following operations.
ConnectedComponents( int N )
starts a new graph
on the vertices 0, 1, 2, ..., N-1 with no edges.
addEdge( int i, int j )
adds a new edge.
areConnected(int i, int j)
returns true if the vertices
i
and j
are connected by a path of edges
in the graph.
minConnected( int i )
finds the smallest numbered
vertex which is connected to vertex i.
getNumPointerTraversals()
is used to gather statistics
about the traversal pattern.
Field Summary | |
protected int |
numPointerTraversals
The total number of pointer traversals |
Constructor Summary | |
ConnectedComponents(int N)
Constructor for a ConnectedComponents object
which is initially for a total disconnected
graph on N vertices. |
Method Summary | |
int |
addEdge(int i,
int j)
Modifies the graph by adding an (undirected) edge between vertices i and j . |
boolean |
areConnected(int i,
int j)
Tests whether two vertices are in the same connected component. |
int |
getNumPointerTraversals()
Returns the total number of pointer traversals. |
int |
minConnected(int i)
Find the minumum numbered vertex which is in the same connected component as i . |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
protected int numPointerTraversals
Constructor Detail |
public ConnectedComponents(int N)
ConnectedComponents
object
which is initially for a total disconnected
graph on N
vertices. The vertices in the graph
are numbered from 0 to N-1.N
- the number of vertices in the graph.Method Detail |
public int addEdge(int i, int j)
i
and j
. The connected components are updated
accordingly.i
- the first vertexj
- the second vertexpublic int minConnected(int i)
i
.i
- a vertex numberi
.public boolean areConnected(int i, int j)
i
- a vertex numberj
- a vertex numbertrue
iff the vertices are in the same connected
component.public int getNumPointerTraversals()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |