GRAPH VS TREE
- Graphs have loops
- Trees do not have cycles. For example, imagine any tree in your head, branches do not have direct connections to the root, but branches have connections with other branches up "
But in case of AI Graph-search vs Tree-search
A graph search has the good property that whenever an algorithm examines a new node and marks it as visited, "Regardless of the algorithm used," the algorithm usually examines all the other nodes that are reachable from the current node.
For example, consider the following graph with three vertices AB and C and consider the following edges
AB, BC and CA, well, there is a cycle from C to A,
And when the DFS, starting from A, A will generate a new state B, B will generate a new state C, but when C is examined, the algorithm will try to create a new state A, but A has already been visited, so it will ignore it. Cool!
But what about trees? tree tree algorithm is not marked by visited node as visited, but trees have no cycles, how would it end up in infinite cycles?
Consider this tree with three vertices and consider the following edges
A - B - C, based on A, down. And suppose we use the DFS algorithm
A will generate a new state B, B will generate two states A and C because the trees do not have “Mark a node if it was examined”, therefore, perhaps the DFS algorithm will examine A again, a new state B, so we we get an infinite loop.
But you noticed something, we are working on non-oriented edges, that is, there is a connection between AB and BA. Of course, this is not a cycle, because a cycle means that the vertices must be> = 3, and all the vertices are different except for the first and last nodes.
ST A-> B-> A-> B-> A is not a cycle, because it violates the cycling property> = 3. But really A-> B-> C-> A - cycle> = 3 Checked nodes, the first and last node will be the same.
Again, consider the edges of the tree, A-> B-> C-> B-> A, of course, this is not a cycle, because there are two Bs, which means that not all nodes are different.
Finally, you can implement a tree search algorithm to double-examine the same node. But this has consequences.