change the recursive algorithm of calculating paths to an iterative algorithm