20

I quote from Artificial Intelligence: A Modern Approach:

The properties of depth-first search depend strongly on whether the graph-search or tree-search version is used. The graph-search version, which avoids repeated states and redundant paths, is complete in finite state spaces because it will eventually expand every node. The tree-search version, on the other hand, is not complete [...]. Depth-first tree search can be modified at no extra memory cost so that it checks new states against those on the path from the root to the current node; this avoids infinite loops in finite state spaces but does not avoid the proliferation of redundant paths.

I don't understand how can graph-search be complete and tree-search be not, being a tree a particular graph.

Besides, I don't clearly get the difference between "infinite loops" and "redundant paths"...

May someone explain this to me?

ps. For those who have the book it's page 86 (3rd edition).

Gilles 'SO- stop being evil'
  • 92,660
  • 35
  • 189
  • 229
Manlio
  • 10,328
  • 9
  • 44
  • 76

2 Answers2

16

Depth-first tree search can get stuck in an infinite loop, which is why it is not "complete". Graph search keeps track of the nodes it has already searched, so it can avoid following infinite loops.

"Redundant paths" are different paths which lead from the same start node to the same end node. Graph search will still explore all these redundant paths, but once it reaches a node which it has visited before, it will not go any further, but will back up and look for more paths which it hasn't tried yet.

This is different from an "infinite loop" which is a path which leads from a node back to itself.

In response to your comment, look at the quote which you just posted:

Depth-first tree search can be modified at no extra memory cost so that it checks new states against those on the path from the root to the current node.

So while depth-first tree search does keep track of the path from the root to the current node, to avoid infinite loops, it needs to do a linear search over that path each time it visits a new node. If you wrote an implementation of depth-first tree search which didn't do that check, it could get into an infinite loop.

You are right, what the book said about the "proliferation of redundant paths" doesn't relate to completeness. It is just pointing out a difference between graph and tree search. Because tree search just keeps track of the current path, it can run over the same path more than once in the same search (even if doing the check I just mentioned).

Say your root node has 2 branches. Each of those branches leads to the same single node, which has a long path leading out from it. Tree search will follow that long path twice, once for each of the 2 branches which leads to it. That is what the author is pointing out.

Alex D
  • 28,136
  • 5
  • 72
  • 115
  • Even tree-search keeps track of the visited nodes (at least, from the root to the current node), thus I don't understand how can it get stuck in an infinite loop. Besides, I now understand the difference between "infinite loop" and "redundant path" (+1), but I don't think this is related with completeness since, even if the path is redundant, it will eventually find a goal node... – Manlio Feb 12 '12 at 17:12
  • Of course, if I do not check for repeated nodes I may get in an infinite loop. How can this be if I do check for repeated nodes? – Manlio Feb 12 '12 at 17:28
  • If you do check for repeated nodes (in a depth-first tree search), you won't get into an infinite loop. That's what your textbook is saying. – Alex D Feb 12 '12 at 18:27
  • So tree-search with occurrences check is actually complete? I think it's a little bit confusing that the book make a differentiation between graph-search and tree-search while it is enough to say "both are complete only with occurrences check". Seems he's pointing out a difference that does not exists... – Manlio Feb 12 '12 at 21:51
  • 1
    I looked carefully at page 86 of the book, and it really seems that it's saying what I think it's saying. Yes, it is confusing to put things in those terms. When the author refers to "depth-first tree search", the assumption seems to be that it does *not* check for repeated nodes. He seems to view the version which checks for repeated nodes as a special case. – Alex D Feb 13 '12 at 05:01
  • Talking with some guys at the university we get to the conclusion that, with "graph-search" and "tree-search" the authors are addressing the algorithms written at page 77 and they are not talking about depth-first applied to graph or tree; this means that "tree-search", for how it's defined, doesn't include occurrences check, thus it's not complete. However thanks for your help :) – Manlio Feb 13 '12 at 19:26
  • 2
    I think the reason why "tree-search" is defined to *not* include the repeated node check, is because this adds an extra O(log N) operation to each step of the search, making the algorithm O(N log N) rather than O(N)... and that's for a *balanced* tree. With a badly unbalanced tree, it could even become O(N^2). – Alex D Feb 13 '12 at 21:22
  • `You are right, what the book said about the "proliferation of redundant paths" doesn't relate to completeness.` I think it does. You can still get stuck in an infinite loop because you're still not keeping track of visited nodes (you're just making sure the path you're on is loop-free). This means you could explore some path `a`, then some path `b`, then again back to path `a`, then `b` and so on. – Peeyush Kushwaha Sep 20 '18 at 07:55
  • @PeeyushKushwaha That cannot happen infinitely in a correctly implemented tree search. – Alex D Sep 21 '18 at 10:02
  • @AlexD how so? In graph search DFS you usually prevent this from happening by storing nodes you have visited. Say `x` has children `a` and `b` and `x`, `a` is on the path you are currently exploring. When you backtrack to `x` then take `b`, then backtrack again to `x`, how do you know you're "done" exploring all children of `x`? – Peeyush Kushwaha Sep 22 '18 at 02:50
  • @PeeyushKushwaha The information stored on the stack must be enough to determine which children still need to be visited. For example, if the children of each node are stored in an array, typically the "current index" of the branch being explored would be stored on the stack. After backtracking, you would increment that index to get the next branch to explore. It would be nonsensical to implement a tree search in any other way. – Alex D Sep 22 '18 at 23:27
  • @Alex D, The last paragraph makes a mistake, if there are two branches from the root node to the same node, it means there is a circle in a tree! So this example is actually a graph search(with circle) example but not a tree search example. – debug Sep 06 '20 at 15:13
  • @debug, see the above comment by Manlio. He correctly states that when the book talks about "depth-first tree search", it is referring to a specific algorithm, regardless of whether that algorithm is applied to a graph or a tree. You may argue that the book's terminology is wrong; if so, please take it up with the author. In the context of this thread, the paragraph is correct as written. – Alex D Sep 07 '20 at 07:10
1

DFS is incomplete(in tree-search). However, if you keep track of visited nodes, it turns to be complete(in graph search).

  1. let's be clear about what completeness means.

If an algorithm is complete, it means that if at least one solution exists then the algorithm is guaranteed to find a solution in a finite amount of time.

  1. We need to distinguish between tree-search and graph-search. As shown in section 3.3 or page 77 in Artificial Intelligence: A Modern Approach, the only difference is that graph-search has a set to store the explored nodes.

  2. Finally, we can figure out the answer.

  • In tree-search(not store explored nodes), since we don't know whether the current node is explored or not, DFS may explore it again(and again...), which will loop forever. -> Infinite time, not complete
  • In graph-search(store explored nodes), any search algorithms will end. -> Finite time, complete