tikz 创建数字搜索树

tikz 创建数字搜索树

我想创建一个像这样的数字搜索树:

数字搜索树

我已经知道如何获得这样的结构

\documentclass[12pt]{article}
\usepackage{tikz}
\tikzstyle{vertex}=[draw,circle,minimum size=20pt,inner sep=0pt]

\begin{document}
\begin{tikzpicture}[thick,level/.style={sibling distance=60mm/#1}]
\node [vertex] {}
    child {
        node [vertex] {}
        child {
            node [fill=blue!15, vertex] {}
            child {
                node [vertex] {}    
                child {
                    node [fill=blue!15, vertex] {}          
                }
                child {
                    node [fill=blue!15, vertex] {}          
                }
                child {
                    node [fill=blue!15, vertex] {}
                    child {
                        node [fill=blue!15, vertex] {}          
                    }           
                }       
            }
            child {
                node [fill=blue!15, vertex] {}          
            }
        }
        child {
            node [fill=blue!15, vertex] {}
        }
    };
\end{tikzpicture}

\end{document}

但是我该如何添加箭头和箭头侧面的文字呢?

答案1

在此处输入图片描述

使用forest包裹并不是那么困难:-)

\documentclass[border=3mm,12pt]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\tikzset{
ELS/.style = {% Edge Label Style
              pos=0.5, node font=\scriptsize, 
              inner sep=2pt, anchor=#1},
        }

\begin{document}
    \begin{forest}
for tree = {
% nodes
    circle, draw, fill=blue!15,
    minimum size=20pt,inner sep=0pt,
% tree
    grow' = south,
    s sep = 12mm,
    l sep = 6mm,
     edge = {semithick,-Stealth},
    where level = 3{s sep=7mm}{}
        },
EL/.style={if n=1{edge label={node[ELS=west]{#1}}}
                 {edge label={node[ELS=east]{#1}}}}
%%%% tree
[,fill=white
    [,fill=white,EL=d
        [,EL=er]
        [,EL=a
            [,EL=mpf]
            [,fill=white,EL=u
                [,EL=er
                    [,EL=n]
                ]
                [,edge label={node[ELS=east,right] {men}}]
                [,EL=ne]
            ]
        ]
    ]
]
    \end{forest}
\end{document}

相关内容