Reformulate the Backtrack procedure so that it halts when th

Reformulate the Backtrack procedure so that it halts when the first goal is reached

Solution

In backtraking we hae to call many functions recursively, (each function leads to its unique path, and gives value, this value may be our goal )..so for many functions, we get many values(goals returned..),then we will select the optimal one, this is how the backtracking works...

so.. here saying that, when the first goal is reached the backtrack proceduces has to halt...

to achieve this.. one method is..

we need to declare a global variable (or static variable) first,(which is initialized to zero..)

this is global variable must be checked first while executing every procedure...(for every recursive function)

if this variable is zero, we can continue the procedure, if not we have to stop here and return.

now, whenever the first goal is reached, we have to set this global variable to one, and return..

by, this every procedure stops, and backtrack procedure halts..

Reformulate the Backtrack procedure so that it halts when the first goal is reachedSolutionIn backtraking we hae to call many functions recursively, (each funct

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site