How to find Sub-trees in non-binary tree

Posted by kenny on Programmers See other posts from Programmers or by kenny
Published on 2012-01-10T09:15:09Z Indexed on 2012/04/09 23:47 UTC
Read the original article Hit count: 361

Filed under:
|
|

I have a non-binary tree.
I want to find all "sub-trees" that are connected to root.

Sub-tree is a a link group of tree nodes.

enter image description here

every group is colored in it's own color.

What would be be the best approach? Run recursion down and up for every node?

The data structure of every treenode is a list of children, list of parents. (the type of children and parents are treenodes)

Clarification:

Group defined if there is a kind of "closure" between nodes where root itself is not part of the closure.
As you can see from the graph you can't travel from pink to other nodes (you CAN NOT use root).
From brown node you can travel to it's child so this form another group.

Finally you can travel from any cyan node to other cyan nodes so the form another group

© Programmers or respective owner

Related posts about java

Related posts about algorithms