广度优先搜索

180 阅读1分钟

定义

执行过程

搜索范围从起点开始逐渐向外延伸,即先检查一度关系,再检查二度关系。由于需要按照添加顺序进行检查,因此使用的数据结构为队列(先入先出)。

工作原理

while queue is not empty  
   take out one element  
   if the element match the condition  
      returnelse  
     tag the element is checked;  
 return