For example, in Figure \[sub\_all\], $V_1$ is mapped to ${\textbf{g}}_6$ and ${\textbf{g}}_3$, but $V_2$ is mapped to ${\textbf{g}}_1$, a subtree of both ${\textbf{g}}_6$ and ${\textbf{g}}_3$; hence $V_{1}$ is only mapped to the green part of ${\textbf{g}}_{6}$ and ${\textbf{g}}_{3}$ as depicted in the Figure. The precise mapping of nodes in ${\textbf{T}}$ to subtrees of ${\textbf{g}}$ described below is needed to allocate mutations in [**T**]{} to branches of ${\textbf{g}}$. We will explain the allocation of mutations on ${\textbf{g}}$ for a given ${\textbf{a}}{}$ in the next subsection.

![image](subtree_allocations-eps-converted-to){width=".5\textwidth"}

We now define an algorithm to efficiently find all possible mappings [**a**]{} for a given ${\textbf{g}}{}$. We encode the set of all possible [**a**]{}, as an $\#{\textbf{a}}\times (n-1)$ matrix $\mathbf{A}$, where each row is a possible ${\textbf{a}}{}$ ($n-1$ columns) and the number of rows $\#{\textbf{a}}$ is equal to the number of possible allocations. To generate $\mathbf{A}$, the algorithm proceeds recursively from top to bottom in [**g**]{}, by sweeping through subtrees in [**g**]{} and matching them to nodes in $\mathbf{T}$ according to parent-offspring relationships and number of descendants in both [**T**]{} and [**g**]{}. To be more precise, the algorithm is initialized by setting the $1 \times (n-1)$ $\mathbf{A}$ matrix to $\mathbf{A}=(V_0,\ldots,V_0)$, *i.e.*, $V_0$ is mapped to 