hi all
hope that all of u are fine : )
well i want to draw a tree not a binary tree but i can't find an efficient algorithm
to draw it
the big problem when the tree is unbalanced
Thanks ur help will be greatly appreciated : )
hi all
hope that all of u are fine : )
well i want to draw a tree not a binary tree but i can't find an efficient algorithm
to draw it
the big problem when the tree is unbalanced
Thanks ur help will be greatly appreciated : )
First, you should show some effort. The best form of effort to show is some of your own code, best if it actually works to do something (maybe not the right thing); or if you cannot get it to compile then show the code and the errors you get from the compiler/interpreter. Be sure to use the code button to place CODE tags around your code.
If you are really just talking about an algorithm that is not tied to a particular programming language, then please be more specific: "the big problem" is not a useful description of what goes wrong. Do you expect that recursion will fail? Does the graphic overflow the bounds of the screen? Are you unable to decide which direction to begin laying out subtrees? These specific details are needed to allow us to understand.
A simple method for drawing binary trees can be generalised to non-binary trees. Okay, so for binary trees, do an inorder traversal of the tree, and draw each node as you visit it. Each node is placed at (x, y) as follows: how many nodes were visited before this one, and y is the depth (or height, you choose) of the node.
To generalise it to non binary trees, instead of visiting the left child, then the node, then the right child, split the children into 2 halves. Visit the first half of the children, then the node itself, then the second half.
I can't really give code at the moment, but I hope I've explained myself clearly enough.
Keep well
M
Glad to help :)