← comparison · doc/tree.md

Trees generation

Jngen provides a Tree class. It offers some methods to manipulate with trees and static generators. As other Jngen objects, Tree can be printed to std::ostream. Here is a standard way to use generators:

cout << Tree::random(100).shuffled() << endl;

Generators

Note that all generators return trees with sorted edges to make tests more human-readable. More, numbering is not always random for same reason. Particularly, Tree::random(size, elongation) always returns a tree rooted at 0. You can always use tree.shuffle() to renumerate vertices and shuffle edges.

random(int size)

randomPrim(int size, int elongation = 0)

randomKruskal(int size)

bamboo(int size)

star(int size)

caterpillar(int size, int length)

Tree binary(int size)

Tree kary(int size, int k)

Tree fromPruferSequence(const Array& code)

Tree methods

Tree& shuffle()

Tree shuffled() const

Tree& shuffleAllBut(const Array& except)

Tree shuffledAllBut(const Array& except)

t = Tree::randomPrim(n, 1000);
t.shuffleAllBut({0});

Array parents(int root) const

Tree link(int vInThis, const Tree& other, int vInOther)

Tree glue(int vInThis, const Tree& other, int vInOther)