What is the problem
You want to draw a complete n-ary tree of h levels, but you keep running out of horizontal space for your nodes as you add deeper levels.
Spoiler alert: you avoid this completely by drawing the tree from the ground up.
Strategy
- Draw the deepest level’s nodes evenly spaced across your page.
There will be exactly of them.
- Move up one level. Place a parent node centered directly above each group of
nnodes.
(e.g., ifn = 2, place one parent node to encompass every pair). - keep doing this going up, until reaching the topmost level, that contains a single node, the root.