Can someone describe through code a practical example of backtracking with iteration instead of recursion?

Posted by chrisapotek on Stack Overflow See other posts from Stack Overflow or by chrisapotek
Published on 2012-12-08T22:04:11Z Indexed on 2012/12/08 23:04 UTC
Read the original article Hit count: 435

Recursion makes backtracking easy as it guarantees that you won't go through the same path again. So all ramifications of your path are visited just once. I am trying to convert a backtracking tail-recursive (with accumulators) algorithm to iteration. I heard it is supposed to be easy to convert a perfectly tail-recursive algorithm to iteration. But I am stuck in the backtracking part.

Can anyone provide a example through code so myself and others can visualize how backtracking is done? I would think that a STACK is not needed here because I have a perfectly tail-recursive algorithm using accumulators, but I can be wrong here.

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about data-structures