3

I was hoping to get some help drawing a binomial queue with the forest package. All I can find are references to binomial trees, but I am looking to replicate this:

enter image description here

I tried using phantom to make spaces but it didn't really work how I wanted it to:

\begin{forest}
  for tree={circle,l=14mm,s sep=10mm,draw}
  [23
    [,phantom]
    [51]
    [24
      [,phantom]
      [65]
    ]
  ]
 \end{forest}

enter image description here

Any help it much appreciated!

4

A simple rude solution:

\documentclass[margin=3mm]{standalone}
\usepackage{forest}

\begin{document}
    \begin{forest}
for tree={circle,l=14mm,s sep=10mm,draw}
[23
    [,phantom]
    [,phantom]
    [51]
    [24
        [,phantom]
        [65]
    ]
]
    \end{forest}
\end{document}

enter image description here

a little bit more "advance" solution

\documentclass[margin=3mm]{standalone}
\usepackage{forest}

\begin{document}
    \begin{forest}
for tree={circle, l=14mm, s sep=7mm, draw, 
          calign=first} % <---
[23
    [,phantom]
    [51]
    [24
        [,phantom]
        [65]
    ]
]
    \end{forest}
\end{document}

Result is similar as before.

5

It is possible to avoid the phantoms altogether by using calign=fixed edge angles, as in the manual on the top of p. 41. And I would define a style for that.

\documentclass{article}
\usepackage{forest}
\forestset{binomial queue/.style={calign=fixed edge angles,calign primary
angle=30,calign secondary angle=60,
  for tree={if n children={1}{grow=-60}{calign=fixed edge
  angles,calign primary angle=30,calign secondary angle=60},
  circle,draw,text width=width("23"),align=center}}}
\begin{document}
\begin{forest}
  binomial queue
  [23
    [51]
    [24
      [65]
    ]
  ]
\end{forest}

\begin{forest}
  binomial queue,
  for tree={s sep+=1em}
  [12
    [21]
    [24
      [65]
    ]
    [14
      [26]
      [16
        [18]
      ]
    ]
  ]
\end{forest}
\end{document}

enter image description here

EDIT: Replaced where by if as suggested by @cfr, thanks!

  • @cfr Thanks! Even if I was not as jet lagged as I am now, I would most likely miss these subtle but important points. I'll correct it ASAP. – Schrödinger's cat Oct 19 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.