How to get trees more balanced?

it looks balanced when the tree itself is actually balanced:

demo6

but it’s being skewed If I add an 6 in this way:

demo7

can I force graphviz to lay out in a balanced way?

Would you explain more about what balanced means in this case. Maybe just a pencil sketch.

Maybe a seemingly obvious brute force algorithm would suffice here? I’m not sure what’s considered state of the art now, but we need to handle arbitrary fanout, and variable width nodes.

something like this:

maybe I should call it “symmetric”, despite how many children a node has?

Simplest (?) way is to define invisible nodes that are used to “fill out” the tree to make it symmetric

digraph T{
  node [shape=circle width=.6]
  10 -> { 85 30 7}
  85 -> { 31 15 40}
  30 -> {63 1 "15a" [label="15"]}

    7 // define visible node
    node [label="" style=invis]
    edge [style=invis]
    7 -> {dummy1 dummy2 dummy3 }
}

Giving:

1 Like