Breadth-first search (BFS) is a graph search algorithm that begins at the root node and explores all the neighboring nodes. Then for each of those nearest nodes, it explores their unexplored neighbor nodes, and so on, until it finds the goal.
Depth-first search (DFS) is an algorithm for traversing or searching a tree, tree structure, or graph. Intuitively, one starts at the root (selecting some node as the root in the graph case) and explores as far as possible along each branch before backtracking.
2007-05-10 20:48:36
·
answer #1
·
answered by nAsHDi 1
·
1⤊
0⤋
A tree is a graph as well. Nitpick :)
This is not specific to C. They are the basic methods applicable to pretty much any searching process, anywhere.
An analogy might serve: Let's say you lost your keys.
Breadth-First Search:
Go into hallway. See if you see your keys.
Go into dining room. Are they there?
Go into bedroom. Can you see them?
Hmm, no more rooms, must be in one of them, I just didn't look hard enough.
Back to hallway. Is it in the drawer? No, just a purse here. On the rack? No, nothing there except clothes.
Back to dining room. Look into various pieces of furniture.
Back to bedroom. Is it on the bed? No, just the bedding. The nightstand?
Oh well. Time for an even more detailed sweep.
In hallway, there was a purse in the drawer - is it in there? No? There were clothes on the rack - is it in there? FOUND THEM!
Depth-first search:
I'll start with the living room. If I can't see them at a glance, I should check each piece of furniture. For example, this wardrobe: I can't see my key, but there are some clothes. These trousers? Nothing in the pockets but some old wallet... Maybe inside the wallet? No. What else is there in the wardrobe? Check everything thoroughly.
Once I'm sure it's not in the wardrobe, start checking other furniture in the living room - in detail. Only after completely elliminating any possibility that the keys might be in the living room, I'll move on to the next room. Once I start checking the hallway in such minute detail, one item at a time, I will find them inside the coat, after I start inspecting the rack.
2007-05-10 23:55:54
·
answer #2
·
answered by amadanmath 3
·
1⤊
0⤋
Difference Between Bfs And Dfs
2017-01-02 18:54:20
·
answer #3
·
answered by ? 4
·
0⤊
0⤋
The other answer is 95% correct. He forgot to mention that BFS vs. DFS also applies to trees, not just graphs.
Of course, if you don't know that trees and graphs are, you need a course in "data structures" ASAP. And that's a junior level college computer science course.
2007-05-10 21:16:56
·
answer #4
·
answered by Kasey C 7
·
1⤊
0⤋
just type in google.. difference between bfs and dfs.. you will find the ans.. trust me.. i did it.. when i had been preparing for my 2nd year MCA exam..
2016-03-19 03:11:46
·
answer #5
·
answered by Ellen 3
·
0⤊
0⤋