In a companion paper [Neugebauer, R., van der Laan, M.J., 2006b. Causal effects in longitudinal studies: definition and maximum likelihood estimation. Comput. Stat. Data. Anal., this issue, doi: 10.1016/j.csda.2006.06.013], we provided an overview of causal effect definition with marginal structural models (MSMs) in longitudinal studies. A parametric MSM (PMSM) and a non-parametric MSM (NPMSM) approach were described for the representation of causal effects in pooled or stratified analyses of treatment effects on time-dependent outcomes. Maximum likelihood estimation, also referred to as G-computation estimation, was detailed for these causal effects. In this paper, we develop new algorithms for the implementation of the G-computation estimators of both NPMSM and PMSM causal effects. Current algorithms rely on Monte Carlo simulation of all possible treatment-specific outcomes, also referred to as counterfactuals or potential outcomes. This task becomes computationally impracticable (a) in studies with a continuous treatment, and/or (b) in longitudinal studies with long follow-up with or without time-dependent outcomes. The proposed algorithms address this important computing limitation inherent to G-computation estimation in most longitudinal studies. Finally, practical considerations about the proposed algorithms lead to a further generalization of the definition of NPMSM causal effects in order to allow more reliable applications of these methodologies to a broader range of real-life studies. Results are illustrated with two simulation studies. (c) 2006 Elsevier B.V. All rights reserved.