Can someone explain the first search?

Can someone explain the Width search to solve the problems below alt text

I need to find all the way between 4 and 7

+4
source share
5 answers

You look at all the nodes located near your beginning node. Then you look at all the nodes adjacent to them (not returning to the nodes that you have already looked at). Repeat until you find a node or no more nodes.

Regarding the problem that you are pointing out, you are using the process described above to create a set of paths ending with any that arrive at your desired destination node, and when your schedule is exhausted, a set of paths that have stopped this is your set of solutions.

+5
source

The first breadth-first search (BFS) means that you process all the direct child nodes of your start nodes before moving to deeper levels. BFS is implemented with a queue that stores a list of nodes that need to be processed.

Run the algorithm by adding node to the queue. Then you continue to run your algorithm until you have nothing left to process in the queue.

When you remove an item from the queue, it becomes the active node. When you process the active node, you add all its children to the back of the queue. You complete the algorithm when you have an empty queue.

Since you are dealing with a graph instead of a tree, you need to keep a list of processed nodes so that you do not enter the loop.

Once you reach node 7, you have the appropriate path and you can stop the execution of BFS for this recursive path. This means that you simply do not add your children to the queue. To avoid loops and find out the exact path you have visited since you are making recursive BFS calls, skip already visited nodes.

+4
source

Think of it as sites with links to other sites. Let A be our root node or our initial website.

  A is the starting page (Layer 1)
 A links to AA, AB, AC (Layer 2)
 AA links to AAA, AAB, AAC (Layer 3)
 AB links to ABA, ABB, ABC (Layer 3)
 AC links to ACA, ACB, ACC (Layer 3)

These are just three layers. You are viewing one layer at a time. Thus, in this case, you start from level A. If this does not correspond, you go to the next layer, AA, AB and AC. If none of these sites is the one you are looking for, you will follow the links and go to the next layer. In other words, you are viewing one layer at a time.

The first search for depth (its complement) you will go from A to AA to AAA. In other words, you must go DEEP before moving to WIDE.

+3
source

You are testing each node connected to the root of the node. Then you test each node connected to previous nodes. So, until you find your answer.

Basically, each iteration checks the nodes at the same distance from the root of the node.

+2
source

TO BEGIN

4;

4.2;

4.2.1; 4.2.3; 4.2.5;

4.2.1; (failure) 4,2,3,6; 4,2,5,6; 4,2,5,11;

4,2,3,6,7; (passage) 4,2,3,6,8; 4,2,5,6,7; (travel) 4,2,5,6,8; 4,2,5,11,12;

4,2,3,6,8,9; 4,2,3,6,8,10; 4,2,5,6,8,9; 4,2,5,6,8,10; 4,2,5,11,12; (failure)

4,2,3,6,8,9 (failure) 4,2,3,6,8,10 (failure) 4,2,5,6,8,9 (failure) 4, 2,5,6, 8.10; (failure)

END

+1
source

All Articles