Generalized error path algorithm