Search algorithm by width

What is a search algorithm in width?

The breadth search algorithm (Breadth First Search - BFS for short) walks through a wide graph and uses a queue to memorize adjacent vertices to start the search when no peak is found. adjacent in any loop.

Search algorithm by width Picture 1

As shown in the example above, the search algorithm broadcasts from A to B to E to F then to C , to G and finally to D. This algorithm follows the rule:

Rule 1 : Browse to the adjacent vertices without approval. Mark the vertex that has been approved. Show that peak and push into a queue (queue) .

Rule 2 : If no adjacent vertices are found, then delete the first vertex in the queue.

Rule 3 : Repeat Rule 1 and 2 until the queue is empty.

The following table illustrates how search-width algorithms work with a simple example:

Queue initialization (queue)

Search algorithm by width Picture 2

We start browsing vertex S (start vertex) and mark this vertex as approved.

Search algorithm by width Picture 3

Then we find the vertex adjacent to S that has not been approved. In this example we have 3 vertices, and in alphabetical order we select vertex A marked as approved and put A in the queue.

Search algorithm by width Picture 4

Continue to browse vertices adjacent to S as B. Mark as approved and place this vertex in the queue.

Search algorithm by width Picture 5

Continue to browse vertices adjacent to S as C. Mark as approved and place this vertex in the queue.

Search algorithm by width Picture 6

Now vertex S has no adjacent vertices that have not been approved yet. Now we draw A from the queue.

Search algorithm by width Picture 7

From vertex A we have an adjacent vertex of D and an unopened vertex. Marking vertex D is already browsing and queuing.

Search algorithm by width Picture 8

At this point, we see that no vertices are unmarked (not yet approved with the example in this table). But the algorithm continues, we continue to extract vertices from the queue in order to find all vertices that have not been approved. When the queue is empty, it is the end of the algorithm.

According to Tutorialspoint

Previous lesson: Deep search algorithm

Next lesson: Tree data structure

4.5 ★ | 4 Vote

May be interested

  • What is algorithm?What is algorithm?
    algorithms (also known as algorithms - english is algorithms) is a finite set of instructions to be executed in a certain order to get the desired result. in general, the algorithm is independent of programming languages, ie an algorithm can be deployed in many different programming languages.
  • Box Model (Box Model) in CSSBox Model (Box Model) in CSS
    elements in html can be considered boxes. in css, the term 'box model' is used to refer to design and layout.
  • Shell Sort in data structure and algorithmShell Sort in data structure and algorithm
    shell sort is a highly efficient sorting algorithm based on insertion sorting algorithm (insertion sort). this algorithm avoids the case of swapping positions of two distant elements in the selection algorithm (if the smaller element is in the right position quite far from the larger element on the left).
  • How does YouTube algorithm work?How does YouTube algorithm work?
    have you ever wondered how youtube algorithm works?
  • Google changed the search ranking algorithm, limiting the display of fake newsGoogle changed the search ranking algorithm, limiting the display of fake news
    see how google changes the search ranking algorithm, limiting the display of fake news!
  • Google 'prioritizes' sites that use HTTPS protocolGoogle 'prioritizes' sites that use HTTPS protocol
    google is quietly changing some of the algorithms included in the ranking list of sites returned from google search. accordingly, google will favor web sites that use https security protocols.
  • Selection sort algorithm (Selection Sort)Selection sort algorithm (Selection Sort)
    selection sort is a simple algorithm. this sorting algorithm is an algorithm based on in-place comparison, in which the list is divided into two parts, sorted (list) on the left and unsorted (unsorted list) in the right. initially, the sorted part is blank and the unordered part is the original list.
  • Quick Sort (Quick Sort)Quick Sort (Quick Sort)
    quick sort is a highly efficient algorithm and is based on dividing the array into smaller pieces.
  • Build high quality sites to improve search resultsBuild high quality sites to improve search results
    in recent months, google has paid special attention to the issue of helping people find high quality results pages.
  • Google Panda - Algorithm for real rankings?Google Panda - Algorithm for real rankings?
    recently, google has updated an important component of ranking websites that affected 12% of search results and reduced the number of visits for many sites. here's how to find out whether the webstie you have - will be affected and what you should do to deal with it.