Drawing trees without degree restrictions

I am working on a visualization of my distributed algorithm that solves problems on trees.

I need to draw a root tree that is given as input.

Currently, I know how to handle the case if each node has no more than 2 children. In this situation, for each node, vdraw vas a circle with coordinates (x(v), x(y)), where:

x(v) := index of v in the inorder traversal
y(v) := distance from v to the root

This works well (of course, the width of the tree is quite large, but it does not bother me much), but only for most binary trees.

Please indicate which algorithm I should use for shared trees. The only requirement I have is that the drawing must be flat.

EDIT:

the simpler algorithm is to implement, the better
+4
2

" " , m-ary :

  • node , x 0
  • , ,
  • node

, , . :

6: node .

Python implementation , .

+3

(, ), .

, , ASCII. , - .

+3

All Articles