I am trying to create figures that illustrate how binary trees may be represented using array indices. Therefore I would like each node in my tree to have two labels: One inside the note, representing its value, and one above the node, representing its index in the array. I have already created a satisfactory figure, but I feel there should be a better way to create the figure.
This is my figure:
This is the code that produced the figure:
\documentclass{article}
\usepackage{tkz-graph}
\GraphInit[vstyle = Normal]
\begin{document}
\begin{tikzpicture}
\tikzset{VertexStyle/.style = {draw, thick, circle, fill=yellow!80}}
\SetGraphUnit{1.6}
\Vertex[LabelOut=true, Lpos=90, Ldist=.12cm, L=\texttt{1}]{a}
\Vertex{4}
\SOWELabelOut=true, Lpos=90, Ldist=.12cm, L=\texttt{2}{b}
\SOWE(4){3}
\begin{scope}
\SetGraphUnit{1}
\SOWELabelOut=true, Lpos=90, Ldist=.12cm, L=\texttt{4}{d}
\SOWE(3){2}
\SOEALabelOut=true, Lpos=90, Ldist=.12cm, L=\texttt{5}{e}
\SOEA(3){1}
\Edge(3)(2)
\Edge(3)(1)
\end{scope}
\SOEALabelOut=true, Lpos=90, Ldist=.12cm, L=\texttt{3}{c}
\SOEA(4){2}
\begin{scope}
\SetGraphUnit{1}
\SOWELabelOut=true, Lpos=90, Ldist=.12cm, L=\texttt{6}{f}
\SOWEL=1{1a}
\SOEALabelOut=true, Lpos=90, Ldist=.12cm, L=\texttt{7}{g}
\SOEAL=1{1b}
\Edge(2)(1a)
\Edge(2)(1b)
\end{scope}
\Edge(4)(3)
\Edge(4)(2)
\end{tikzpicture}
\end{document}
In order to create the labels, I drew each node (or vertex) twice: Once for the top label, and again for the bottom label. Is there another way using tkz-graph? I realize there may be better ways to draw binary trees, but this will also be useful for more general graphs.
Many thanks for all help.


forest? – Oct 12 '18 at 20:57\tikzset{mynode/.style={above,yshift=0.3cm}}and inside the tikzpicture:\node[above,yshift=0.3cm] at (a) {1}... This can be included in your Vertex (or a new style) I think in order to have two parameters and the second will be the number 1 of my example but have no the time to test it now... Tested just that the \node works. – koleygr Oct 12 '18 at 21:03\Vertex{4}and then in the next line\node[above, yshift=0.4cm] at (4){1};? Or did I misunderstand? – Erik André Oct 12 '18 at 21:12