Beam Search Basics-Breadth First and depth first

Source: Internet
Author: User
Overview

This paper introduces the basic concept of depth first and breadth first search method.

Open Table saves paths that have not been visited
The close table saves the visited path, preventing entry into a dead loop. Specific Algorithms

Accessing all reachable vertices from one of the start nodes is useful in many scenarios, such as how do we want to traverse from H to C in the following image?
The specific steps from H, to find the direct successor of H {b,d, L}, thus constituting the three candidate path {h->b,h->d,h->l}, at this time {b,d,l} becomes open vertices will open vertices (and the path to which they belong) are placed in the open table. Select a vertex from the open table to remove the open table and generate a successor to this vertex
For example, we chose L, whose successor is {m,f,h}, because H has been visited, so it cannot be placed in the open table, otherwise it will cause a dead loop, so there is {b,d,m,f} in the Open table.
To prevent a dead loop, there will be a close table that records the points that have been visited, and once a point enters the close table, it will never be accessed the second time so continue knowing that the target vertex is found or the target vertex is not found

Note: Breadth first or depth first is entirely determined by the way data is accessed from the Open table
* Open Table is advanced and out is the depth first
* Open Table is FIFO is the breadth first example and pseudo code depth First sample

at left)
Vertex visited (and hence closed) Open list (stack top
H B D L
B D d L
D G J D L
G J J D L
J E I M J D L
E K I M J D L
K I M J D L
I F M J D L
F A l M J D L
A L M J D L
L M m J D L
M C M J D L
C M J D L
Depth-first pseudo-code
/* Initialization *
/Queue openlist = {Startvertex}

/* loop *
/while (closednodes! = Numberofnodes &&am p;!openlist.empty ())
{
  Closingvertex = Openlist.dequeue ();
  Increment number of closednodes;

  For each non-closed vertex not in the openlist, and with a
     edge to it from Closingvertex
  {
    Openlist.enqueue (v Ertex);
  }

}
Breadth First similar References

Http://jhave.org/algorithms/graphs/depthbreadth/depth-breadth.shtml

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.