0

I am trying to convert this recursive algorithm in an iterative one, it is the ida A* algorithm (from wikipedia). I have implemented it and the iterative version doesn't return the same result as the recursive version.

 function search(node, bound)
   if state.f > bound then return state.f
   if is_goal(node) then return FOUND
   min := ∞
   for succ in successors(node) do
     t := search(succ, bound)
     if t = FOUND then return FOUND
     if t < min then min := t
   end for
  return min
 end function

First attempt

 function search(node, bound)
   stack = new Stack()
   stack.push(node)
   while(!stack.empty())
     state = stack.pop()
     min := ∞
     if state.f > bound then 
       if state.f < min then min := state.f
       continue
     if is_goal(node) then return FOUND
     for succ in successors(node) do
       stack.push(succ)
     end for
   return min
  end function
blob
  • 439
  • 8
  • 21
  • 2
    This is too simplistic to capture the running behavior of the recursive version. You need to keep track of separate `min` values for each level in the _tree_. – 500 - Internal Server Error Feb 17 '17 at 16:48
  • I delete the if with continue and I can use inside the for loop: "if succ.f > bound then min =min(minimum, succ.f) else stack.push(succ)" but it doesnt' work – blob Feb 17 '17 at 17:26

0 Answers0