Problem with binary tree

tikz-pgftikz-treestrees

I am drawing AVL trees using tikz. I have this code:

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}
\begin{center}
    \begin{tikzpicture}
    \node[circle,draw](z){19}
    child{node[circle,draw]{16}
    child{node[circle,draw]{11}}
    child{node[circle,draw]{17}}}
    child{node[circle,draw]{21}
    child{node[circle,draw]{20}}
    child{node[circle,draw]{26}}};
    \end{tikzpicture}
\end{center}
\end{document}

It should be a balanced AVL tree. The right child of the 16 should be 17 and the left child of the 21 should be 20. With the code I get this

enter image description here

As you can see the 17 and the 20 are fused as one node. How can I solve this problem without modifying all other trees that I have drawn already?

Thanks for your answers!

Best Answer

You can specify a sibling distance for each level.

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}
    \begin{center}
        \begin{tikzpicture}[
                every node/.style={circle, draw},
                level 1/.style={sibling distance=6em},
                level 2/.style={sibling distance=3em},
            ]
            \node (z){19}
            child{node {16}
                child{node {11}}
                child{node {17}}}
            child{node {21}
                child{node {20}}
                child{node {26}}};
        \end{tikzpicture}
    \end{center}
\end{document}

enter image description here

I have also added a style for every node, which cleans up your code.