Given a graph $G$ with $n$ vertices, a vertex-degree-based topological index is defined from a set of real numbers $\left\{ \varphi _{ij}\right\} $ as $TI\left( G\right) =\sum m_{ij}\left( G\right) \varphi _{ij}$, where $m_{ij}\left( G\right) $ is the number of edges between vertices of degree $i$ and degree $j$, and the sum runs over all $1\leq i\leq j\leq n-1$. Let $\Omega \left( n,2\right) $ denote the set of all trees with $n$ vertices and $2$ branching vertices. In this paper we give conditions on the number $\{\varphi_{ij}\}$ under which the extremal trees with respect to $TI$ can be determined. As a consequence, we find extremal trees in $\Omega \left( n,2\right) $ for several well-known vertex-degree-based topological indices.