Algorithm to compute separate path