Click to See Complete Forum and Search --> : [RESOLVED] BFS & DFS Algorithm


Backslash
April 13th, 2009, 01:02 AM
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.

SlickHawk
April 13th, 2009, 09:07 AM
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.