Last active
July 16, 2025 23:37
-
-
Save brianmed/39c9bfc0b35f721e7761b00a45818000 to your computer and use it in GitHub Desktop.
Graphviz dot of a mathematical expression in a binary tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/questions/23429600/how-do-i-make-a-dot-graph-representing-a-binary-tree-more-symmetric | |
digraph G | |
{ | |
nodesep=0.4; //was 0.8 | |
ranksep=0.5; | |
label="((10 - 25) + (40 * 50))" | |
{ node[style=invis, label=""]; cx_root; } | |
{ node[style=invis, label="", width=.1]; ocx_001_multiply_symbol; ocx_001_minus_symbol; } | |
{ node[label="+"]; "000_plus_symbol"; } | |
{ node[label="-"]; "001_minus_symobl"; } | |
{ node[label="*"]; "001_multiply_symbol"; } | |
{ rank=same; "001_minus_symobl"; "001_multiply_symbol"; cx_root } | |
{ rank=same; 10; 25; ocx_001_minus_symbol } | |
{ rank=same; 40; 50; ocx_001_multiply_symbol } | |
"000_plus_symbol" -> "001_minus_symobl"; | |
"000_plus_symbol" -> "001_multiply_symbol"; | |
"001_minus_symobl" -> 10; | |
"001_minus_symobl" -> 25; | |
"001_multiply_symbol" -> 40; | |
"001_multiply_symbol" -> 50; | |
{ | |
edge[style=invis]; | |
//Distantiate nodes | |
"000_plus_symbol" -> cx_root; | |
"001_minus_symobl" -> cx_root -> "001_multiply_symbol"; | |
//Force ordering between children | |
"001_multiply_symbol" -> ocx_001_multiply_symbol; | |
40 -> ocx_001_multiply_symbol -> 50; | |
"001_minus_symobl" -> ocx_001_minus_symbol; | |
10 -> ocx_001_minus_symbol -> 25; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment