Help me about the Breadth-First-Search?? [Archive] - C Board

PDA

View Full Version : Help me about the Breadth-First-Search??


john_tran
04-09-2005, 03:25 AM
I dont know how to input the start-information of the tree like this:
A-> B -> C - > D
A-> E -> F
B-> G
C-> G -> H -> I
D-> K
Find the way from A to I by BFS
What data structure i wish to use?? And how to declare it.
Can you give me an example or a shortcut code?
Thanks alot
John

Magos
04-12-2005, 05:25 AM
Breath-first is a memory consuming search method, but is guaranteed to find a solution if one exists, even if the tree has infinite depth. The basic implementation is a queue.

1) Push root to queue
2) If queue is empty, stop with failure
3) Pop element from queue (name it A)
4) If A is the goal node, stop with success
5) Push all child nodes of A to to the queue
6) Repeat from 2)