I need to paint a different path on the tree to figure two different situations that happen on the tree. In particular, I'm able to figure the travers tree with a forest, as the figure below, and this will figure my cases from root -> leaf.
But I need also to figure the cases from the leaf -> root with different colors and different arrows that point from child to parent and I don't know where to start.
\documentclass[letterpaper,12pt]{article}
\usepackage{blindtext}
\usepackage{tikz}
\usepackage{forest}
\usepackage{xcolor}
\usepackage{float}
\usetikzlibrary{calc}
\newcounter{nodeidx}
\newcounter{example}
\setcounter{nodeidx}{1}
\usetikzlibrary{
calc,
arrows.meta,
%shapes.multipart,
%arrows
}
\newcommand{\nodes}[1]{%
\foreach \num [count=\n starting from 0] in {#1}{% no need for an external counter
\node[minimum size=6mm, draw, rectangle] (n\n) at (\n,0) {\num};
}
}
\begin{document}
\begin{figure}[H]
\centering
\begin{forest}
for tree = {
rectangle split,
rectangle split horizontal,
rectangle split parts=10,
rectangle split ignore empty parts,
draw,
%
parent anchor=south,
child anchor=north,
calign=edge midpoint,
edge = {-Stealth, semithick},
l sep=6mm,
where level=0{s sep=11mm}{s sep=3mm},
}
[2 \nodepart{two} 4 \nodepart{three} 3 \nodepart{four} 1 \nodepart{five} 6
\nodepart{six} 7 \nodepart{seven} 8 \nodepart{eight} 9 \nodepart{nine} 1 \nodepart{ten} 7, color={red}
[2\nodepart{two} 2 \nodepart{two} 4 \nodepart{three} 3 \nodepart{four} 1 \nodepart{five} 6
[2\nodepart{two} 4
[2] [4]]
[3\nodepart{two} 1 \nodepart{three} 6
[3] [1 \nodepart{two} 6
[1] [6]
]]
]
[7 \nodepart{two} 8 \nodepart{three} 9 \nodepart{four} 1
\nodepart{six} 7,fit=band, color={red}
[7 \nodepart{two} 8
[7]
[8]
]
[9\nodepart{two} 1 \nodepart{three} 7, color={red}
[9]
[1\nodepart{two} 7, color={red}
[10, color={green}]
[7]
]
]
]
]
\end{forest}
\end{figure}
\end{document}
Thanks for the help.