Foundational theory for optimal decision tree problems. I. Algorithmic and geometric foundations