mercredi 7 janvier 2015

How to randomly get or find a sub-tree (include root node) from a given tree that contains n nodes


I have a non-binary tree. I want to randomly find a "sub-trees" that are connected to root which must have at least n nodes. For example: given a tree as below



A
/ \
B C
/ \ \
E D F
\
J


n = 4

A random sub-tree that contains 4 nodes could be:



A
/
B
\
D
\
J


or



A
/ \
B C
\
F


I don't need to get all possible sub-trees, just randomly get it with a given tree and n





Aucun commentaire:

Enregistrer un commentaire