I'm trying to draw a binary tree using tikz
package.
If I use only circle
, I get a tree. But I want to represent a subtree
using a triangle
. Now the tree gets uneven. I want to attach the arrows to the top of the triangle
and also want the size of the triangle
comparable to the size of the circle
.
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usetikzlibrary{shapes.geometric,arrows,fit,matrix,positioning}
\tikzset
{
treenode/.style = {circle, draw=black, align=center, minimum size=1cm},
subtree/.style = {isosceles triangle, draw=black, align=center, minimum height=0.5cm, minimum width=1cm, shape border rotate=90, anchor=north}
}
\begin{document}
\begin{figure}[t]
\centering
\caption{An illustration of a simple delete operation. \label{fig:simple}}
{
\begin{tikzpicture}[->,>=stealth',level/.style={sibling distance = 5cm/#1,
level distance = 1.5cm},scale=0.6, transform shape]
\node [treenode] {$X$ \\ 100}
child
{
node [treenode] {$Y$ \\ 50}
child
{
node [treenode] {$Z$ \\ 40}
child
{
node [treenode] {$S1$ \\ 30}
}
child
{
node [treenode] {$S2$ \\ 60}
}
}
child
{
node [subtree] {$Z$ \\ 200}
}
}
child
{
node [subtree] {$Z$ \\ 200}
}
;
\end{tikzpicture}
}
\end{figure}
\end{document}