V - the graph vertex typeE - the graph edge typepublic class PruferTreeGenerator<V,E> extends Object implements GraphGenerator<V,E,V>
A Prüfer sequence of length $n$ is randomly generated and converted into the corresponding tree.
This implementation is inspired by "X. Wang, L. Wang and Y. Wu, "An Optimal Algorithm for Prufer Codes," Journal of Software Engineering and Applications, Vol. 2 No. 2, 2009, pp. 111-115. doi: 10.4236/jsea.2009.22016." and has a running time of $O(n)$.
| Constructor and Description |
|---|
PruferTreeGenerator(int n)
Construct a new PruferTreeGenerator.
|
PruferTreeGenerator(int[] pruferSequence)
Construct a new PruferTreeGenerator from an input Prüfer sequence.
|
PruferTreeGenerator(int n,
long seed)
Construct a new PruferTreeGenerator.
|
PruferTreeGenerator(int n,
Random rng)
Construct a new PruferTreeGenerator
|
| Modifier and Type | Method and Description |
|---|---|
void |
generateGraph(Graph<V,E> target,
Map<String,V> resultMap)
Generates a tree.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgenerateGraphpublic PruferTreeGenerator(int[] pruferSequence)
pruferSequence - the input Prüfer sequenceIllegalArgumentException - if n is ≤ 0IllegalArgumentException - if pruferSequence is nullIllegalArgumentException - if pruferSequence is invalid.public PruferTreeGenerator(int n)
n - number of vertices to be generatedIllegalArgumentException - if n is ≤ 0public PruferTreeGenerator(int n,
long seed)
n - number of vertices to be generatedseed - seed for the random number generatorIllegalArgumentException - if n is ≤ 0public PruferTreeGenerator(int n,
Random rng)
n - number of vertices to be generatedrng - the random number generator to useIllegalArgumentException - if n is ≤ 0NullPointerException - if rng is nullpublic void generateGraph(Graph<V,E> target, Map<String,V> resultMap)
Note: An exception will be thrown if the target graph is not empty (i.e. contains at least one vertex)
generateGraph in interface GraphGenerator<V,E,V>target - the target graphresultMap - not used by this generator, can be nullNullPointerException - if target is nullIllegalArgumentException - if target is not undirectedIllegalArgumentException - if target is not emptyCopyright © 2019. All rights reserved.