Árvore de recursão em LaTeX

Árvore de recursão em LaTeX

Como a seguinte árvore de recursão pode ser desenhada em LaTeX?

desejado

Eu tentei usar o TikZ fotos para isso, mas continuo recebendo erros no código. Por favor, sugira um código mais fácil para o mesmo.

Responder1

Você pode usar o poderosoforestpacote; você pode até deixar os cálculos de conteúdo por conta do pacote:

insira a descrição da imagem aqui

O código:

\documentclass[border=5pt]{standalone}
\usepackage{amsmath}
\usepackage{forest}

\begin{document}

\begin{forest}
for tree={
  parent anchor=south,
  s sep=2pt
},
delay={for descendants={
  if n=1
    {draw,content/.wrap 2 pgfmath args=
      {$c\binom{n}{#2}^{2}$}{content}{int(2^level)}}
      {if n'=1{draw,content/.wrap 2 pgfmath args=
        {$c\binom{n}{#2}^{2}$}{content}{int(2^level)}}{}
      },  
     where n children={0}{draw,content=c}{}
  }
}
[$cn^{2}$,draw
  [
    [
      [
        []
        []
        []
      ]
      [
        [,phantom]
      ]
      [
        [,phantom]
      ]
      [
        []
        []
        []
      ]
    ]
    [
      [,phantom]
    ]
    [
      [,phantom]
    ]
    [
      [
        []
        []
        []
      ]
      [
        [,phantom]
      ]
      [
        [,phantom]
      ]
      [
        []
        []
        []
      ]
    ]
  ]
  [
    [,phantom [,phantom]]
  ]
  [
    [,phantom [,phantom]]
  ]
  [
    [
      [
        []
        []
        []
      ]
      [
        [,phantom]
      ]
      [
        [,phantom]
      ]
      [
        []
        []
        []
      ]
    ]
    [
      [,phantom]
    ]
    [
      [,phantom]
    ]
    [
      [
         []
        []
        []
     ]
      [
        [,phantom]
      ]
      [
        [,phantom]
      ]
      [
        []
        []
        []
      ]
    ]
  ]
]
\end{forest}

\end{document}

Responder2

forestpermite que você especifique uma árvore usando a notação de colchetes padrão. Verminha resposta a uma pergunta anteriorpara obter uma explicação de como transformar uma árvore em uma especificação usando notação de colchetes. Outras respostas abrangem outros pacotes adequados para desenhar árvores simples (conforme especificado na pergunta). Então, se você não gosta forest, talvez um dos outros sirva.

Para forest, aqui está um protótipo para você começar:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\begin{document}

\begin{forest}
  for tree={
    draw,
    align=center
  }
  [root
    [child
      [grandchild
        [great\\-grandchild]
        [great\\-grandchild]
        [great\\-grandchild]
      ]
      [grandchild, calign with current]
      [grandchild
        [great\\-grandchild]
        [great\\-grandchild]
        [great\\-grandchild]
      ]
    ]
    [child
      [grandchild
        [great\\-grandchild]
        [great\\-grandchild]
        [great\\-grandchild]
      ]
      [grandchild, calign with current]
      [grandchild
        [great\\-grandchild]
        [great\\-grandchild]
        [great\\-grandchild]
      ]
    ]
    [child
      [grandchild
        [great\\-grandchild]
        [great\\-grandchild]
        [great\\-grandchild]
      ]
      [grandchild, calign with current]
      [grandchild
        [great\\-grandchild]
        [great\\-grandchild]
        [great\\-grandchild]
      ]
    ]
    [child
      [grandchild
        [great\\-grandchild]
        [great\\-grandchild]
        [great\\-grandchild]
      ]
      [grandchild, calign with current]
      [grandchild
        [great\\-grandchild]
        [great\\-grandchild]
        [great\\-grandchild]
      ]
    ]
  ]
\end{forest}


\end{document}

protótipo

informação relacionada