CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2009
    Posts
    26

    [RESOLVED] BFS & DFS Algorithm

    I attached the original graph below and my highlighted BFS version. I wanted to see if my order is correct. Also I have to do a DFS algorithm but I don't know how. Can someone tell me what's it all about.
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Join Date
    Mar 2009
    Posts
    19

    Re: BFS & DFS Algorithm

    From what I can see, your BFS looks correct.

    The difference between a BFS and a DFS is very minimal. A BFS algorithm looks something like this:

    1. Place the starting node on a list.
    2. If the list is empty, end. Else, remove the head of the list.
    3. If that node has already been visited, discard it and go to 2.
    4. Else, visit that node and stick all its children at the end of the list. Go to 2.

    That may be changed to a DFS very simply. Instead of placing the current node's children at the END of the list, place them at the BEGINNING. That's it. Same algorithm otherwise.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured