0

I want to do some manual tracing of algorithms involving trees. I'd like to be able to create printable trees with empty nodes, like the one shown below, but to at least a couple more levels of depth. I'd also like to be able to have different numbers of branches - i.e. binary, ternary, quaternary trees etc.

Can anyone recommend a tool or tool/syntax combination for getting this done with the least cognitive overhead please?

enter image description here

Robin Andrews
  • 3,514
  • 11
  • 43
  • 111
  • Thanks. Any tips on syntax for ternary tree please? – Robin Andrews Oct 31 '22 at 15:52
  • I've tried installing it but issues with paths, and not trivial ones. Plenty of questions on SO. Easier to use a whiteboard. Shame as I would have thought it's a common enough task. – Robin Andrews Oct 31 '22 at 17:16
  • Installation is dead simple. Download the dot program, either to the folder where you want to run from, or somewhere on your path, Done! Some more details https://forum.graphviz.org/t/new-simplified-installation-procedure-on-windows/224 – ravenspoint Oct 31 '22 at 19:29
  • It's in my path. Python can't find it. – Robin Andrews Oct 31 '22 at 19:33
  • Forget about python! You just need the dot program and a command window to run it from – ravenspoint Oct 31 '22 at 19:36

1 Answers1

1

To produce

enter image description here

First create the g.dot file

graph {
a [label="root"]
b [label=""]
c [label=""]
d [label=""]
ba [label=""]
ca [label=""]
da [label=""]
bc [label=""]
cc [label=""]
dc [label=""]
bd [label=""]
cd [label=""]
dd [label=""]
a -- { b c d }
b -- { ba ca da }
c -- { bc cc dc }
d -- { bd cd dd }
}

Then run the graphviz dot program

dot -Tpng -o sample.png g.dot
ravenspoint
  • 19,093
  • 6
  • 57
  • 103