0

I'm trying to explain the execution time of an algorithm and I'm using the forest as a package to drawing tree, and with this post, I'm asking if is possible to draw the same tree in the figure below with the package forest. Form the forest quick start I don't see an example like that.

enter image description here

  • Can you post some code? Do you have code for tikz-qtree or something? (You've tagged the question with that.) The answer to the question is: yes, you can do this with Forest. – cfr Dec 08 '20 at 05:31
  • 1
    https://tex.stackexchange.com/q/302864/, https://tex.stackexchange.com/q/404588/, ... There are lots of examples on the site. – cfr Dec 08 '20 at 05:42
  • Fantastic, thanks :) – vincenzopalazzo Dec 08 '20 at 10:57
  • @vincenzopalazzo -- just stumbled across this exact replica at --- https://texample.net/tikz/examples/merge-sort-recursion-tree/ -- though not with forest -- have alook below – js bibra Dec 08 '20 at 12:01
  • unfortunately, I need to do this with the forest and not with tikzpicture – vincenzopalazzo Dec 08 '20 at 14:06
  • Why do you need to do it with forest particularly? forest is just a(n extremely sophisticated) wrapper around tikzpicture. – cfr Dec 10 '20 at 05:45
  • People are more likely to help with the tree if you provide the content of the nodes .... At least, I am. Too much work looking back and forth between editor and image. – cfr Dec 10 '20 at 05:54
  • @cfr I agree, but I open this post to collect some opinions, like yours in this subsection. I was able to use the documentation of tikzpicture to make the tree inside the question, but I was curious if was possible to use the forest. Why forest?, because I'm new with latex and I don't want to add unnecessary tools that I need to understand and learn in a small-time. – vincenzopalazzo Dec 10 '20 at 08:40

1 Answers1

1

enter image description here

% MergeSort-RecursionTree
% Manuel Kirsch
\documentclass[a4paper,landscape]{scrartcl}
\usepackage{fancybox}
\usepackage{tikz}

\title{MergeSort-RecursionTree} \author{Manuel Kirsch} \date{} \begin{document}

\ovalbox{ \begin{tikzpicture}[level/.style={sibling distance=60mm/#1}] \node [circle,draw] (z){$n$} child {node [circle,draw] (a) {$\frac{n}{2}$} child {node [circle,draw] (b) {$\frac{n}{2^2}$} child {node {$\vdots$} child {node [circle,draw] (d) {$\frac{n}{2^k}$}} child {node [circle,draw] (e) {$\frac{n}{2^k}$}} } child {node {$\vdots$}} } child {node [circle,draw] (g) {$\frac{n}{2^2}$} child {node {$\vdots$}} child {node {$\vdots$}} } } child {node [circle,draw] (j) {$\frac{n}{2}$} child {node [circle,draw] (k) {$\frac{n}{2^2}$} child {node {$\vdots$}} child {node {$\vdots$}} } child {node [circle,draw] (l) {$\frac{n}{2^2}$} child {node {$\vdots$}} child {node (c){$\vdots$} child {node [circle,draw] (o) {$\frac{n}{2^k}$}} child {node [circle,draw] (p) {$\frac{n}{2^k}$} child [grow=right] {node (q) {$=$} edge from parent[draw=none] child [grow=right] {node (q) {$O_{k = \lg n}(n)$} edge from parent[draw=none] child [grow=up] {node (r) {$\vdots$} edge from parent[draw=none] child [grow=up] {node (s) {$O_2(n)$} edge from parent[draw=none] child [grow=up] {node (t) {$O_1(n)$} edge from parent[draw=none] child [grow=up] {node (u) {$O_0(n)$} edge from parent[draw=none]} } } } child [grow=down] {node (v) {$O(n \cdot \lg n)$}edge from parent[draw=none]} } } } } } }; \path (a) -- (j) node [midway] {+}; \path (b) -- (g) node [midway] {+}; \path (k) -- (l) node [midway] {+}; \path (k) -- (g) node [midway] {+}; \path (d) -- (e) node [midway] {+}; \path (o) -- (p) node [midway] {+}; \path (o) -- (e) node (x) [midway] {$\cdots$} child [grow=down] { node (y) {$O\left(\displaystyle\sum_{i = 0}^k 2^i \cdot \frac{n}{2^i}\right)$} edge from parent[draw=none] }; \path (q) -- (r) node [midway] {+}; \path (s) -- (r) node [midway] {+}; \path (s) -- (t) node [midway] {+}; \path (s) -- (l) node [midway] {=}; \path (t) -- (u) node [midway] {+}; \path (z) -- (u) node [midway] {=}; \path (j) -- (t) node [midway] {=}; \path (y) -- (x) node [midway] {$\Downarrow$}; \path (v) -- (y) node (w) [midway] {$O\left(\displaystyle\sum_{i = 0}^k n\right) = O(k \cdot n)$}; \path (q) -- (v) node [midway] {=}; \path (e) -- (x) node [midway] {+}; \path (o) -- (x) node [midway] {+}; \path (y) -- (w) node [midway] {$=$}; \path (v) -- (w) node [midway] {$\Leftrightarrow$}; \path (r) -- (c) node [midway] {$\cdots$}; \end{tikzpicture}}

\end{document}

js bibra
  • 21,280
  • 1
    unfortunately, I need to do this with the forest and not with tikzpicture, this doesn't answer at my question. Sorry – vincenzopalazzo Dec 08 '20 at 14:07
  • @vincenzopalazzo If this doesn't answer your question, you shouldn't accept it because fewer people will read your question if it is marked as answered. – cfr Dec 10 '20 at 05:46
  • I accepted this because the previous answer (now not longer exists), not answer me and propose another tool. for the moment is the only question try to answer me. – vincenzopalazzo Dec 10 '20 at 08:35