Click here to Skip to main content
15,905,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi...
I found that in some tutorial the breadth first search

the shallow nodes are expanded befor deeper nodes.

I am realy confuse what is the meaning of each of them?

Thank you
Posted

1 solution

Consider a tree data structure where starting from the root node there are anything from zero to n children for any node in the tree. BFS just visits all the m children of any node before it descends to inspect the next deeper level while DFS always tries to descend to the next level as soon as it finds a node that still has child nodes.

Cheers!
 
Share this answer
 
v2
Comments
dedoooo 18-Dec-11 9:16am    
Ok but let say we have a tree with 3 nodes , the right child and left child have the same depth from the root , (equals number of edges ,right? so why expand the left child first?
Manfred Rudolf Bihy 18-Dec-11 15:51pm    
Left to right or right to left or any other order are all the same regarding BFS & DFS as this only concerns the order of processing the children of a node.
Manfred Rudolf Bihy 18-Dec-11 15:53pm    
In implementing a special version of DFS or BFS you are free to choose any direction in child traversal that you fancy or even a non linear traversal would be fine for example choosing the next child node randomly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900