Package algs41
Class GraphGenerator
java.lang.Object
algs41.GraphGenerator
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic GraphbinaryTree(int V) Returns a complete binary tree graph onVvertices.static Graphbipartite(int V1, int V2, double p) Returns a random simple bipartite graph onV1andV2vertices, containing each possible edge with probabilityp.static Graphcomplete(int V) static Graphconnected(int V, int E) static Graphconnected(int V, int E, int c) static Graphstatic Graphcycle(int V) Returns a cycle graph onVvertices.static GrapheulerianCycle(int V, int E) Returns an Eulerian cycle graph onVvertices.static GrapheulerianPath(int V, int E) Returns an Eulerian path graph onVvertices.static GraphCreate a graph from input stream.static voidstatic Graphpath(int V) Returns a path graph onVvertices.static voidstatic Graphrandom(int V, int E) static Graphregular(int V, int k) Returns a uniformly randomk-regular graph onVvertices (not necessarily simple).static Graphsimple(int V, int E) static GraphsimpleConnected(int V, int E) static GraphspanningTree(int V) static Graphstar(int V) Returns a star graph onVvertices.static Graphtree(int V) Returns a uniformly random tree onVvertices.static Graphwheel(int V) Returns a wheel graph onVvertices.
-
Constructor Details
-
GraphGenerator
public GraphGenerator()
-
-
Method Details
-
fromIn
Create a graph from input stream. -
copy
-
complete
-
simple
-
simpleConnected
-
connected
-
random
-
spanningTree
-
connected
-
bipartite
Returns a random simple bipartite graph onV1andV2vertices, containing each possible edge with probabilityp.- Parameters:
V1- the number of vertices in one partitionV2- the number of vertices in the other partitionp- the probability that the graph contains an edge with one endpoint in either side- Returns:
- a random simple bipartite graph on
V1andV2vertices, containing each possible edge with probabilityp - Throws:
IllegalArgumentException- if probability is not between 0 and 1
-
path
Returns a path graph onVvertices.- Parameters:
V- the number of vertices in the path- Returns:
- a path graph on
Vvertices
-
binaryTree
Returns a complete binary tree graph onVvertices.- Parameters:
V- the number of vertices in the binary tree- Returns:
- a complete binary tree graph on
Vvertices
-
cycle
Returns a cycle graph onVvertices.- Parameters:
V- the number of vertices in the cycle- Returns:
- a cycle graph on
Vvertices
-
eulerianCycle
Returns an Eulerian cycle graph onVvertices.- Parameters:
V- the number of vertices in the cycleE- the number of edges in the cycle- Returns:
- a graph that is an Eulerian cycle on
Vvertices andEedges - Throws:
IllegalArgumentException- if eitherV <= 0orE <= 0
-
eulerianPath
Returns an Eulerian path graph onVvertices.- Parameters:
V- the number of vertices in the pathE- the number of edges in the path- Returns:
- a graph that is an Eulerian path on
Vvertices andEedges - Throws:
IllegalArgumentException- if eitherV <= 0orE < 0
-
wheel
Returns a wheel graph onVvertices.- Parameters:
V- the number of vertices in the wheel- Returns:
- a wheel graph on
Vvertices: a single vertex connected to every vertex in a cycle onV-1vertices
-
star
Returns a star graph onVvertices.- Parameters:
V- the number of vertices in the star- Returns:
- a star graph on
Vvertices: a single vertex connected to every other vertex
-
regular
Returns a uniformly randomk-regular graph onVvertices (not necessarily simple). The graph is simple with probability only about e^(-k^2/4), which is tiny when k = 14.- Parameters:
V- the number of vertices in the graphk- degree of each vertex- Returns:
- a uniformly random
k-regular graph onVvertices.
-
tree
Returns a uniformly random tree onVvertices. This algorithm uses a Prufer sequence and takes time proportional to V log V.- Parameters:
V- the number of vertices in the tree- Returns:
- a uniformly random tree on
Vvertices
-
print
-
main
-