Auteur ou autrice : Olivier Péault.
Mise en ligne le 14 septembre 2023
Cet exemple illustre l’utilisation du package mptrees
présent sur le CTAN. Ce package propose des macros permettant de produire des arbres, dont notamment des arbres probabilistes.
Code
input mptrees;
beginfig(1);
dirtree:=-90;
branchtype:="curve"; tenscurve:=0.75;
linewidth:=1;
linecolor:=(0.2,0.2,0.7);
widthbranch:=1cm; scalebranch:=0.9;
gapnode:=1cm;
leaveformat:="bbox";
nodeformat:="superellipse"; nodebgcolor:=(0.6,0.6,1);
begintree;
label.top(textext("\Large Huffman tree (source Wikipedia)"),(0,1cm));
draw startlabel("36");
draw stree[1][1]()("20","16");
draw stree[2][1]()("12","8");
draw stree[2][2]()("8","8");
draw stree[3][1]()("' '|7","5");
draw stree[3][2]()("4","4");
draw stree[3][3]()("4","'a'|4");
draw stree[3][4]()("4","'e',4");
draw stree[4][2]()("'f'|3","2");
draw stree[4][3]()("'s'|2","'h'|2");
draw stree[4][4]()("2","'i'|2");
draw stree[4][5]()("'m'|2","'t'|2");
draw stree[4][7]()("2","'n'|2");
draw stree[5][2]()("'l'|1","'r'|1");
draw stree[5][5]()("'p'|1","'x'|1");
draw stree[5][9]()("'u'|1","'o'|1");
endtree;
endfig;
end.