  This paper investigates convex quadratic optimization problems involving $n$
indicator variables, each associated with a continuous variable, particularly
focusing on scenarios where the matrix $Q$ defining the quadratic term is
positive definite and its sparsity pattern corresponds to the adjacency matrix
of a tree graph. We introduce a graph-based dynamic programming algorithm that
solves this problem in time and memory complexity of $\mathcal{O}(n^2)$.
Central to our algorithm is a precise parametric characterization of the cost
function across various nodes of the graph corresponding to distinct variables.
Our computational experiments conducted on both synthetic and real-world
datasets demonstrate the superior performance of our proposed algorithm
compared to existing algorithms and state-of-the-art mixed-integer optimization
solvers. An important application of our algorithm is in the real-time
inference of Gaussian hidden Markov models from data affected by outlier noise.
Using a real on-body accelerometer dataset, we solve instances of this problem
with over 30,000 variables in under a minute, and its online variant within
milliseconds on a standard computer. A Python implementation of our algorithm
is available at https://github.com/aareshfb/Tree-Parametric-Algorithm.git.
