Thread: Help me about the Breadth-First-Search??

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    4

    Help me about the Breadth-First-Search??

    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

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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)
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Shortest Path Maze Solver (Breadth Search Help)
    By Raskalnikov in forum C Programming
    Replies: 5
    Last Post: 04-07-2009, 07:41 PM
  2. Using Breadth First Search
    By neandrake in forum C++ Programming
    Replies: 4
    Last Post: 05-06-2005, 05:13 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM