| ||||||||||||||
| ||||||||||||||
|
||||||||||||||
|
This essay will cover very basic tree searches, the depth-first and breadth-first. In artificial intelligence, we use trees to represent a lot of things, from sentence structures, equations and even game states. Often, a method of searching the trees to find a specified goal is required - these algorithms are the simplest methods to do this.
Depth-firstAs the name implies, the depth-first search transverses a tree all the way down a leaf node, before travelling back and searching again. In English, that sentence is best seen in a diagram:
Breadth-firstSimple, instead of exploring the depth-first, it explores the breadth of the tree! Again, here is our diagram pair to help you visualize it:
The AlgorithmsThe algorithms are so similar I will present them to you side-by-side:
This looks a bit confusing at first, but it will clear up upon explanation of OPEN and CLOSED. The OPEN list contains nodes that have not been looked at, and CLOSED contains all the nodes that have been explored. So, initially CLOSED is empty and OPEN is initialized to OPEN. Now, in the first iteration of the loop, we set N to the first element of OPEN (in this case StartNode). StartNode is not a goal node, so we continue. We remove N from the OPEN list, and check whether it is in CLOSED. It won't be, so we add it. We then check for any children of N, and put those on the OPEN list to be explored. Perhaps another diagram and a step-through is necessary.
Depth-first Step-through
Notice where the depth-first and breadth-first algorithms differ though, child items are prepended on the list in depth-first, but appended in breadth-first. ConclusionThe pros and cons of the each method normally are extremely relative to the tree is question, and the problem but hand. Breadth-first searches will always find the closest solution, but depth-first searches can be quicker under some circumstances (when there isn't a close solution) and the depth-first tends to use less memory.
Submitted: 06/11/2000 Article content copyright © James Matthews, 2000.
|
|
|||||||||||||
All content copyright © 1998-2007, Generation5 unless otherwise noted.
- Privacy Policy - Legal - Terms of Use -