I'm trying to illustrate a process of an algorithm over a Binary Search Tree, for which I need to make various figures where each time, different nodes are highlighted.
I wish to highlight these nodes using a vertical arrow that points to them, with a description text above that arrow, as well as color (gray-scale, since the document is intended for printing) highlight of the given node.
This is the code I use for my basic Binary Search Tree(*):
\begin{tikzpicture}[level/.style={sibling distance=30mm/#1}]
\node [circle,draw] (a){$26$}
child {node [circle,draw] (b){$15$}
child {node [circle,draw] (c){$9$}}
child {node [circle,draw] (d){$20$}
child {node [circle,draw] (e){$19$}}
child {node [circle,draw] (f){$24$}}
}
}
child {node [circle,draw] (g){$31$}
child[missing]
child {node [circle,draw] (i){$35$}
child[missing]
child {node [circle,draw] (k){$40$}}
}
};
\end{tikzpicture}
This code, when compiled (in context) will produce the following result:
What I want to achieve is something like this:
I've found this question, which seeks a similar solution, however I don't wish to adjust the style of an existing graph edge, but to add a label that points to a vertex. Is there a way to do it without creating this label as a Tree vertex?
Thanks in advance!
(*) It is only a small part of the entire document. Based on an example by Manuel Kirsch, which can be found here.
Best Answer
The code
will define the node labelled
i
So you have just to complete your
tikzpicture
like this, for example:This may require to load the
positioning
library, see Tikz manualEdit: to make a colored node, you just have to add the relevant keys in the definition of the node (
node[...](i){}
). I'll let you search a little :-)