0

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 : )

Edited by RehabReda: n/a

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by swinefish
0

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.

Edited by happygeek: fixed formatting

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.