# How do I make an unbalanced binary tree?

How do I draw just a tree with one child using tikzpicture?

As shown in the picture, I want to have a tree like (1).

But I have only been succesful in getting a picture like (2) and (3) using:

\begin{tikzpicture}
\node[circle,draw](z){$30$}
% comment the below for (3):
child{}
child{
node[circle,draw]{40}}
;
\end{tikzpicture}


So, is there a modifier that I don't know of? I've tried to find it in the manual of 7xx pages, but I failed on finding something useful.

-

You can use missing children (Section 18.5.3 Missing Children in the pgf manual):

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\node[circle,draw](z){$30$}
child[missing]{}
child{
node[circle,draw]{40} child{node[circle,draw] {20}} child[missing] };
\end{tikzpicture}

\end{document}


-
You're awesome, thanks! –  Lekensteyn Mar 9 '12 at 22:49

You can also do this with tikz-qtree, which has a simpler syntax, especially for large trees and if most of your nodes are balanced, and only a few aren't.

\documentclass{article}
\usepackage{tikz-qtree}
\begin{document}
\tikzset{every tree node/.style={minimum width=2em,draw,circle},
blank/.style={draw=none},
edge from parent/.style=
{draw, edge from parent path={(\tikzparentnode) -- (\tikzchildnode)}},
level distance=1.5cm}
\begin{tikzpicture}
\Tree
[.50
[.60 ]
[.30
\edge[blank]; \node[blank]{};
\edge[]; [.40
\edge[]; {20}
\edge[blank]; \node[blank]{};
]
]
]
\end{tikzpicture}
\end{document}


-
I haven't installed tikz-qtree, but this is a nice, clear example +1 –  Lekensteyn Mar 10 '12 at 10:19
Is there any way to simplify the \edge[blank]; \node[blank]{}; phrase? I seem to be using it a lot! –  Richard Dec 18 '12 at 22:59
@Richard This isn't so easy. See Macro for empty nodes in tikz-qtree. –  Alan Munn Dec 18 '12 at 23:52