TeX - LaTeX Asked by Taken Spark on June 20, 2021
how do I embed a binary tree inside of a child node of an already existing binary tree, like such
I’ve been using tikzpicture to draw the trees this way:
documentclass[12pt, letterpaper, oneside]{article}
usepackage{tikz}
begin{document}
[
begin{tikzpicture}[nodes={draw, circle, fill=gray!20}, --]
node{19}
child {node{25}
child[missing]
child{node{28}
child {node{32}}
child {node{93}}
}
}
child [missing]
child[missing]
child {node{20}
child{node{89}
child{node{99}}
child[missing]
}
child[missing]
};
end{tikzpicture}
]
end{document}
Through the help of a friend, I've managed to come up with a not so hard solution for this tree, I hope it helps someone:
documentclass{article}
usepackage{tikz}
usetikzlibrary{shapes.geometric}
begin{document}
flushleft
begin{tikzpicture}
[square/.style={regular polygon, regular polygon sides=4}]
node at (0,0) [circle,draw] (a) {4};
node at (5,-3) [rounded corners, draw] (c) {
begin{minipage}{0.4textwidth}
begin{tikzpicture}
node at (0,0) [circle,draw] (a1) {8};
node at (1,-1) [circle,draw] (a2) {16};
node at (-1,-1) [circle,draw] (a3) {50};
node at (-2,-2) [circle,draw] (a4) {55};
draw (a1) -- (a2);
draw (a1) -> (a3);
draw (a3) -> (a4);
end{tikzpicture}
end{minipage}
begin{minipage}{0.4textwidth}
begin{tikzpicture}
node at (0,0) [circle,draw] (a1) {19};
node at (2,-1) [circle,draw] (a2) {20};
node at (-2,-1) [circle,draw] (a3) {25};
node at (-1,-2) [circle,draw] (a4) {28};
node at (-1.5,-3) [circle,draw] (a5) {32};
node at (-0.5,-3) [circle,draw] (a6) {93};
node at (1,-2) [circle,draw] (a7) {89};
node at (0.5,-3) [circle,draw] (a8) {99};
draw (a1) -> (a2);
draw (a1) -> (a3);
draw (a3) -> (a4);
draw (a4) -> (a5);
draw (a4) -> (a6);
draw (a2) -> (a7);
draw (a7) -> (a8);
end{tikzpicture}
end{minipage}
};
node at (-3,-1) [circle,draw] (b) {9};
node at (-4,-2) [circle,draw] (b1) {17};
node at (-5,-3) [circle,draw] (b2) {19};
node at (-2,-2) [circle,draw] (b3) {26};
draw (a) -- (c);
draw (a) -- (b);
draw (b) -- (b1);
draw (b1) -- (b2);
draw (b) -- (b3);
end{tikzpicture}
end{document}
Correct answer by Taken Spark on June 20, 2021
This shows how to put an entire tikzpicture into a node. Not sure how to put that node into a tree.
documentclass[12pt, letterpaper, oneside]{article}
usepackage{tikz}
begin{document}
begin{center}
sbox0{begin{tikzpicture}[nodes={draw, circle, fill=gray!20}]
node{19}
child {node{25}
child[missing]
child{node{28}
child {node{32}}
child {node{93}}
}
}
child [missing]
child[missing]
child {node{20}
child{node{89}
child{node{99}}
child[missing]
}
child[missing]
};
end{tikzpicture}}
begin{tikzpicture}
node[draw, rectangle, rounded corners] {usebox0};
end{tikzpicture}
end{center}
end{document}
Answered by John Kormylo on June 20, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP