Posts

Showing posts with the label #BFS

DFS AND BFS TRAVERSAL (AI)

Image
The breadth first search (BFS) and the depth first search (DFS) are the two algorithms used for traversing and searching a node in a graph. They can also be used to find out whether a node is reachable from a given node or not.   Breadth First Search (BFS) Now we take an example of a problem in BFS that is how it works what are the operations we require in order to traverse a graph with the help of BFS. BFS means breath first search that is we can traverse the tree layerwise for example given in below    Here we have have nodes A in layer one nodes B,C,D in layer two nodes E and F in layer three. So now must be clear visiting the Nodes layerwise means what . For visiting a node we have queue maintaining the nodes which are visited . Now lets see the algorithm for BFS for this tree . At the first layer we have A so here by convention we consider A as already marked now search for all nodes which are adjacent to A . Probably we find adjace...