[Tex/LaTex] How to make an unbalanced binary tree

tikz-trees

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).

3 trees

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.

Best Answer

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}

enter image description here

Related Question