Sunday, 15 July 2012

java - Why is this called backtracking? -



java - Why is this called backtracking? -

i have read in wikipedia , have googled it,

but cannot figure out "backtracking algorithm" means.

i saw solution "cracking code interviews"

and wonder why backtracking algorithm?

"backtracking" term occurs in enumerating algorithms.

you built "solution" (that construction every variable assigned value).

it possible during construction, realize solution not successful (does not satisfy constraints), backtrack: undo assignments of values variables in order reassign them.

example:

based on illustration want build path in 2d grid. start generating paths (0,0). instance:

(0,0) (0,0) (1,0) go right (0,0) (1,0) (1,1) go (0,0) (1,0) (1,1) (0,1) go left (0,0) (1,0) (1,1) (0,1) (0,0) go downwards oops, visiting cell sec time, not path anymore backtrack: remove lastly cell path (0,0) (1,0) (1,1) (0,1) (0,0) (1,0) (1,1) (0,1) (1,1) go right oops, visiting cell sec time, not path anymore backtrack: remove lastly cell path ....

java algorithm backtracking

No comments:

Post a Comment