Is there some algorithm for tree data structure visualization? I tried googling, but couldnt find any. I\'m pretty sure there has to be some algorithm for this not that simp
You can also print the tree left-to-right i.e. root at the very left, the first level right to that and so on. You'll find the tree printed with each level on it's own 'column'. The algorithm is somewhat like this:
print(node, spaces):
if node has left child:
print(left_child, spaces + ' ')
print spaces + node + '\n'
if node has right child:
print(right_child, spaces + ' ')
This algorithm will print one tree node per line. Each level of the tree will be indented to the right by some spaces. This algorithm will print the items in ascending order, but the descending order may be achieved by processing the right child first.