类 TransitiveClosure
- java.lang.Object
-
- edu.princeton.cs.algs4.TransitiveClosure
-
public class TransitiveClosure extends java.lang.Object
TheTransitiveClosure
class represents a data type for computing the transitive closure of a digraph.This implementation runs depth-first search from each vertex. The constructor takes time proportional to V(V + E) (in the worst case) and uses space proportional to V2, where V is the number of vertices and E is the number of edges.
For large digraphs, you may want to consider a more sophisticated algorithm. Nuutila proposes two algorithm for the problem (based on strong components and an interval representation) that runs in E + V time on typical digraphs. For additional documentation, see Section 4.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
-
-
构造器概要
构造器 构造器 说明 TransitiveClosure(Digraph G)
Computes the transitive closure of the digraphG
.
-
-
-
构造器详细资料
-
TransitiveClosure
public TransitiveClosure(Digraph G)
Computes the transitive closure of the digraphG
.- 参数:
G
- the digraph
-
-
方法详细资料
-
reachable
public boolean reachable(int v, int w)
Is there a directed path from vertexv
to vertexw
in the digraph?- 参数:
v
- the source vertexw
- the target vertex- 返回:
true
if there is a directed path fromv
tow
,false
otherwise- 抛出:
java.lang.IllegalArgumentException
- unless0 <= v < V
java.lang.IllegalArgumentException
- unless0 <= w < V
-
main
public static void main(java.lang.String[] args)
Unit tests theTransitiveClosure
data type.- 参数:
args
- the command-line arguments
-
-