I have made a node class that contains the node itself and the leftchild as well as the rightchild. I do not know what is the next step.

Terence hiu wrote:Hi guys, i am having difficulties programming a tree structure

.I would like to specify an max depth of an tree and let the program randomly generate nodes for me until max depth is reach.how would i go accross this? I am creating a mathematical expression onto a tree

I have made a node class that contains the node itself and the leftchild as well as the rightchild. I do not know what is the next step.

You need to define what "randomly generate nodes" mean. The "until max depth is reach" part just specify when you stop randomly generating, and makes no reference on how to randomly generate.

Henry

Terence hiu wrote:

from root

* to know the height --> there is recursive algorithm

* for clear understanding I would suggest you to know what is called level order traversal of tree...

Note: in your tree class, parent reference is missing , which play crucial role in most circumstance .. for instance, print a specific path of a tree

Seetharaman Venkatasamy wrote:

Terence hiu wrote:

from root

* to know the height --> there is recursive algorithm

* for clear understanding I would suggest you to know what is called level order traversal of tree...

Note: in your tree class, parent reference is missing , which play crucial role in most circumstance .. for instance, print a specific path of a tree

I know what is tree traveral, it is post order i need. It's jsut i do not know how it is implemented in java

Jayesh A Lalwani wrote:Do you mean you want the value of the nodes to be randomly generated? Assuming that you know how to generate a random string. Just write a recursive function that creates 2 nodes with random string, and puts hem as children of current node. If depth is less than target, call the function recursively

Thankyou. solves part of my problem. im just wondering how i can work out the depth of my tree now