东南方五行属什么| 空气净化器什么牌子好| 人天是什么意思| 满月脸是什么意思| 下巴下面长痘痘是什么原因| 成群结队是什么意思| 六味地黄丸什么时候吃| 嘴唇发紫发黑是什么原因| 斯文败类是什么意思| 壁是什么意思| 冠脉ct能检查出什么| 眼线是什么意思| 茄子有什么功效| 什么的朝霞| 胃出血吃什么药好| 物色是什么意思| 2月18号什么星座| 癸卯是什么意思| 下架是什么意思| 145是什么意思| 能够握紧的就别放了是什么歌| 90年属马的是什么命| 刚字五行属什么| 蒸米饭时加什么好吃| 公检法是什么| 梦见修路什么意思| 胃切除手术后吃什么好| 送同学什么生日礼物好| 什么是996| 为什么会得肺癌| 曹操是什么时期的人| 肚脐眼周围痛挂什么科| 变态是什么意思| 乙脑是什么病| 未属什么五行| 梦见手机失而复得是什么意思| 菊花是什么季节开的| 吃什么对血管好| 吴京为什么看上谢楠| 头皮痛是什么原因| 羊冲什么生肖| 参见是什么意思| 干眼症吃什么药| 缺钾吃什么| 阿斯伯格综合症是什么| 爱拍马屁的动物是什么生肖| only是什么品牌| 八月初八是什么星座| 鼓风机是干什么用的| 墨镜偏光是什么意思| 双肺索条灶是什么意思| 3月16号是什么星座| pd-l1是什么| 肾炎吃什么药好| 嘴唇神经跳动是什么原因| 酸豆角炒什么好吃| 属猪和什么属相相冲| 夏天流鼻血是什么原因| 口干舌燥口苦是什么原因引起的| 什么属于轻微糖尿病| 佛法无边是什么意思| 水命中什么水命最好| 地中海贫血是什么病| 胰岛素针头4mm和5mm有什么区别| 腰肌劳损是什么症状| 做面条用什么面粉| 鸩是什么意思| 玻璃瓶属于什么垃圾| 瓜子脸适合剪什么发型| 高净值什么意思| ky什么意思| 头伏二伏三伏吃什么| ovs是什么品牌| 睡衣什么面料最好| 矢量是什么意思| 梦到头发白了是什么意思| 支气管肺炎吃什么药| 抗组胺是什么意思| 爱而不得是什么意思| 吃了狗肉不能吃什么| 辣皮子是什么| 大姐大是什么意思| 9月10日是什么日子| 额头发黑是什么原因| 做月子吃什么菜| 雷峰塔为什么叫雷峰塔| 支原体感染是什么病| 侏罗纪是什么意思| 样本是什么意思| 激素六项是查什么的| mt指什么| 杨的右边念什么| 胆酷醇高有什么危害| 手筋痛是什么原因| 阴茎不硬吃什么药| 奶油的原料是什么| 想睡睡不着是什么原因| 脊髓炎吃什么药| 咳嗽一直不好是什么原因| 抗核抗体是检查什么的| 身上起疙瘩是什么原因| 怀孕有什么特征| 懵懂是什么意思| zxj是什么意思| 阑尾炎吃什么药见效快| 一路繁花的意思是什么| 风寒感冒吃什么药| tap什么意思| 温州人为什么会做生意| 弥漫性脂肪肝什么意思| 干湿分离什么意思| 大什么小什么| 小孩反复发烧是什么原因| 山楂片泡水喝有什么好处| 卵是什么意思| 铂金是什么材质| 3月7号什么星座| 龋齿挂什么科| 胃肠彩超能检查出什么| 乳腺结节是什么原因引起的| 拜阿司匹灵是什么药| 扁桃体发炎吃什么药效果好| 棕色用什么颜色调出来| dha什么时候吃最好| 刻板是什么意思| 三伏天吃什么好| 什么是理数| 气血两虚吃什么补最快| 色盲色弱是什么意思| 铁剂是什么| 心机重的人弱点是什么| 瞳孔是什么| 苹果什么季节成熟| 治疗幽门螺旋杆菌的四联药是什么| 友女是什么意思| 血塞通治什么病最好| 麾下是什么意思| 怀孕生化了有什么症状| 咳绿痰是什么原因| 月亮五行属什么| 什么时候恢复高考| amazon是什么意思| 18是什么生肖| 腿膝盖后面的窝窝疼是什么原因| 小腹痛吃什么药| 甲状腺实性结节什么意思| 印度为什么叫阿三| 青蛙爱吃什么| 排卵试纸阴性是什么意思| 灿烂的近义词是什么| 就诊是什么意思| 夏天脚底冰凉是什么原因| 人为什么会便秘| 膀胱炎是什么症状表现| 11月7号是什么星座| 天运子什么修为| 海蓝之谜适合什么肤质| 什么牌子的益生菌调理肠胃比较好| 蜜蜡五行属什么| 眼干眼涩眼疲劳用什么眼药水| 身上起红斑是什么原因| 为什么一躺下就鼻塞| 拉水便是什么原因| 汉族为什么叫汉族| 艮什么意思| alba手表是什么牌子| 什么药止汗效果最好| 测骨龄挂什么科| 梦见吃西红柿是什么意思| 梦见白萝卜是什么意思| 什么是结缔组织病| 阿胶是什么| 血常规挂什么科| 时蔬是什么意思| 龙飞凤舞是什么意思| 脾胃伏火是什么意思| 为什么掉头发很厉害| 冬虫夏草什么价格| 枕头底下放剪刀有什么说法| 吃什么能快速降血压| 德不配位是什么意思| 腿麻是什么原因| 大作是什么意思| 8月15号是什么日子| 7.12什么星座| 什么的树林| 小孩流鼻血挂什么科| 孩子打呼噜是什么原因| 7.1是什么星座| 鼓的偏旁部首是什么| 染色体由什么和什么组成| 考试前不能吃什么| 麦粒肿是什么| 知了猴什么时候结束| gi值是什么| 青春永驻什么意思| 羊水透声欠佳什么意思| 智齿长什么样子图片| cov是什么意思| 失信人是什么意思| 男人射的快是什么原因| 我操是什么意思| 排斥是什么意思| 水煮鱼用什么鱼做好吃| 七月三十是什么星座| 什么是叠词| 你算什么东西| ecc是什么意思| 姿态万千的意思是什么| 阻生齿是什么| 什么叫早教| 肾炎是什么症状| 脾切除后有什么影响| 咖位是什么意思| 3月23是什么星座| 脚疼是什么原因引起的| 欲加之罪何患无辞是什么意思| 什么的什么是什么的伞| 什么的风筝| 手串18颗代表什么意思| 候场是什么意思| 圆房是什么意思| 5月3号是什么星座| 鼻子流血什么原因| 隐翅虫咬了用什么药膏| 子宫肌瘤是什么引起的| 咳嗽挂号挂什么科| 魔芋是什么植物| 澳门用什么币种| 咖啡豆是什么动物粪便| 圆房要做什么| 口干舌燥喝水也不解渴是什么原因| 学考成绩什么时候公布| 米醋和白醋有什么区别| 幽门螺旋杆菌有什么危害| 纳米丝是什么面料| 砗磲是什么| 胸闷挂什么科| 虎口长痣代表什么| 女人吃什么能活血化瘀| 未见卵黄囊是什么意思| 布洛芬是什么药| 吃芒果不能和什么一起吃| 肾的功能是什么| 大姨妈延迟是什么原因| 天气热吃什么解暑| 过期的咖啡有什么用途| 喀秋莎什么意思| 爱说梦话是什么原因| 青椒炒什么好吃又简单| 阴虱用什么药治疗| mL代表什么| omega什么意思| impress是什么意思| 什么时候跑步减肥效果最好| 多发性脂肪瘤是什么原因造成的| 体检前三天不能吃什么| 字字珠玑是什么意思| 晚上吃什么水果减肥效果最好| 什么草药能治肿瘤| 没有高中毕业证有什么影响| 甲亢多吃什么食物比较好| 1978年出生是什么命| ipmn是什么意思| 百度

我国肝癌患者的生存获益有望得到进一步提高

百度 会议同意周小平同志辞去四川省网络作家协会主席。

Breadth-first search (BFS) is an algorithm for searching a tree data structure for a node that satisfies a given property. It starts at the tree root and explores all nodes at the present depth prior to moving on to the nodes at the next depth level. Extra memory, usually a queue, is needed to keep track of the child nodes that were encountered but not yet explored.

Animated example of a breadth-first search. Black: explored, grey: queued to be explored later on
BFS on Maze-solving algorithm
Top part of Tic-tac-toe game tree

For example, in a chess endgame, a chess engine may build the game tree from the current position by applying all possible moves and use breadth-first search to find a winning position for White. Implicit trees (such as game trees or other problem-solving trees) may be of infinite size; breadth-first search is guaranteed to find a solution node[1] if one exists.

In contrast, (plain) depth-first search (DFS), which explores the node branch as far as possible before backtracking and expanding other nodes,[2] may get lost in an infinite branch and never make it to the solution node. Iterative deepening depth-first search avoids the latter drawback at the price of exploring the tree's top parts over and over again. On the other hand, both depth-first algorithms typically require far less extra memory than breadth-first search.[3]

Breadth-first search can be generalized to both undirected graphs and directed graphs with a given start node (sometimes referred to as a 'search key').[4] In state space search in artificial intelligence, repeated searches of vertices are often allowed, while in theoretical analysis of algorithms based on breadth-first search, precautions are typically taken to prevent repetitions.

BFS and its application in finding connected components of graphs were invented in 1945 by Konrad Zuse, in his (rejected) Ph.D. thesis on the Plankalkül programming language, but this was not published until 1972.[5] It was reinvented in 1959 by Edward F. Moore, who used it to find the shortest path out of a maze,[6][7] and later developed by C. Y. Lee into a wire routing algorithm (published in 1961).[8]

Pseudocode

edit

Input: A graph G and a starting vertex root of G

Output: Goal state. The parent links trace the shortest path back to root[9]

 1  procedure BFS(G, root) is
 2      let Q be a queue
 3      label root as explored
 4      Q.enqueue(root)
 5      while Q is not empty do
 6          v := Q.dequeue()
 7          if v is the goal then
 8              return v
 9          for all edges from v to w in G.adjacentEdges(v) do
10              if w is not labeled as explored then
11                  label w as explored
12                  w.parent := v
13                  Q.enqueue(w)

More details

edit
 
An example map of Southern Germany with some connections between cities
 
The breadth-first tree obtained when running BFS on the given map and starting in Frankfurt

This non-recursive implementation is similar to the non-recursive implementation of depth-first search, but differs from it in two ways:

  1. it uses a queue (First In First Out) instead of a stack (Last In First Out) and
  2. it checks whether a vertex has been explored before enqueueing the vertex rather than delaying this check until the vertex is dequeued from the queue.

If G is a tree, replacing the queue of this breadth-first search algorithm with a stack will yield a depth-first search algorithm. For general graphs, replacing the stack of the iterative depth-first search implementation with a queue would also produce a breadth-first search algorithm, although a somewhat nonstandard one.[10]

The Q queue contains the frontier along which the algorithm is currently searching.

Nodes can be labelled as explored by storing them in a set, or by an attribute on each node, depending on the implementation.

Note that the word node is usually interchangeable with the word vertex.

The parent attribute of each node is useful for accessing the nodes in a shortest path, for example by backtracking from the destination node up to the starting node, once the BFS has been run, and the predecessors nodes have been set.

Breadth-first search produces a breadth-first tree which is shown in the example below.

Example

edit

The lower diagram shows the breadth-first tree obtained by running a BFS on an example graph of German cities (upper diagram) starting from Frankfurt.

Analysis

edit

Time and space complexity

edit

The time complexity can be expressed as  , as every vertex and every edge will be explored in the worst case.   is the number of vertices and   is the number of edges in the graph. Note that   may vary between   and  , depending on how sparse the input graph is.[11]

When the number of vertices in the graph is known ahead of time, and additional data structures are used to determine which vertices have already been added to the queue, the space complexity can be expressed as  , where   is the number of vertices. This is in addition to the space required for the graph itself, which may vary depending on the graph representation used by an implementation of the algorithm.

When working with graphs that are too large to store explicitly (or infinite), it is more practical to describe the complexity of breadth-first search in different terms: to find the nodes that are at distance d from the start node (measured in number of edge traversals), BFS takes O(bd + 1) time and memory, where b is the "branching factor" of the graph (the average out-degree).[12]:?81?

Completeness

edit

In the analysis of algorithms, the input to breadth-first search is assumed to be a finite graph, represented as an adjacency list, adjacency matrix, or similar representation. However, in the application of graph traversal methods in artificial intelligence the input may be an implicit representation of an infinite graph. In this context, a search method is described as being complete if it is guaranteed to find a goal state if one exists. Breadth-first search is complete, but depth-first search is not. When applied to infinite graphs represented implicitly, breadth-first search will eventually find the goal state, but depth first search may get lost in parts of the graph that have no goal state and never return.[13]

BFS ordering

edit

An enumeration of the vertices of a graph is said to be a BFS ordering if it is the possible output of the application of BFS to this graph.

Let   be a graph with   vertices. Recall that   is the set of neighbors of  . Let   be a list of distinct elements of  , for  , let   be the least   such that   is a neighbor of  , if such a   exists, and be   otherwise.

Let   be an enumeration of the vertices of  . The enumeration   is said to be a BFS ordering (with source  ) if, for all  ,   is the vertex   such that   is minimal. Equivalently,   is a BFS ordering if, for all   with  , there exists a neighbor   of   such that  .

Applications

edit

Breadth-first search can be used to solve many problems in graph theory, for example:

See also

edit

References

edit
  1. ^ that is, a node satisfying the specified property
  2. ^ Cormen Thomas H.; et al. (2009). "22.3". Introduction to Algorithms. MIT Press.
  3. ^ Korf, Richard E. (1985). "Depth-First Iterative Deepening: An Optimal Admissible Tree Search". Artificial Intelligence (27): 99–100. doi:10.7916/D8HQ46X1.
  4. ^ "Graph500 benchmark specification (supercomputer performance evaluation)". Graph500.org, 2010. Archived from the original on 2025-08-07. Retrieved 2025-08-07.
  5. ^ Zuse, Konrad (1972), Der Plankalkül (in German), Konrad Zuse Internet Archive. See pp. 96–105 of the linked pdf file (internal numbering 2.47–2.56).
  6. ^ Moore, Edward F. (1959). "The shortest path through a maze". Proceedings of the International Symposium on the Theory of Switching. Harvard University Press. pp. 285–292. As cited by Cormen, Leiserson, Rivest, and Stein.
  7. ^ Skiena, Steven (2008). "Sorting and Searching". The Algorithm Design Manual. Springer. p. 480. Bibcode:2008adm..book.....S. doi:10.1007/978-1-84800-070-4_4. ISBN 978-1-84800-069-8.
  8. ^ Lee, C. Y. (1961). "An Algorithm for Path Connections and Its Applications". IRE Transactions on Electronic Computers (3): 346–365. doi:10.1109/TEC.1961.5219222. S2CID 40700386.
  9. ^ Cormen, Thomas H. (January 2010). "22.2 Breadth-first search". Introduction to algorithms. Prentice-Hall Of India Pvt. Limited. ISBN 978-81-203-4007-7. OCLC 1006880283.
  10. ^ "Stack-based graph traversal ≠ depth first search". 11011110.github.io. Retrieved 2025-08-07.
  11. ^ Cormen, Thomas H.; Leiserson, Charles E.; Rivest, Ronald L.; Stein, Clifford (2001) [1990]. "22.2 Breadth-first search". Introduction to Algorithms (2nd ed.). MIT Press and McGraw-Hill. pp. 531–539. ISBN 0-262-03293-7.
  12. ^ Russell, Stuart; Norvig, Peter (2003) [1995]. Artificial Intelligence: A Modern Approach (2nd ed.). Prentice Hall. ISBN 978-0137903955.
  13. ^ Coppin, B. (2004). Artificial intelligence illuminated. Jones & Bartlett Learning. pp. 79–80.
  14. ^ Aziz, Adnan; Prakash, Amit (2010). "4. Algorithms on Graphs". Algorithms for Interviews. Algorithmsforinterviews.com. p. 144. ISBN 978-1453792995.
  15. ^ Dhulipala, Laxman; Blelloch, Guy E.; Shun, Julian (August 21, 2019). Theoretically Efficient Parallel Graph Algorithms Can Be Fast and Scalable. p. 17. arXiv:1805.05208. doi:10.1145/3210377.3210414. ISBN 9781450357999. S2CID 44126609.
edit
脉搏跳得快是什么原因 睾酮是什么 衍心念什么 阴道润滑剂什么牌子好 四联用药是些什么药
c反应蛋白是什么 网易是什么 胃下垂吃什么药最好 西咪替丁是什么药 泡脚对身体有什么好处
什么是包皮 一个火一个斤念什么 一个口四个又念什么 小苏打和食用碱有什么区别 dia是什么意思
女性腰酸是什么原因引起的 吕布的马叫什么 内向是什么意思 防是什么生肖 什么的积雪
局灶肠化是什么意思hcv9jop5ns0r.cn 加拿大签证需要什么材料hcv9jop7ns9r.cn 什么生金hcv9jop7ns0r.cn 蓝猫为什么叫蓝猫hcv8jop0ns2r.cn 医保定点医院是什么意思hcv8jop3ns6r.cn
肝气郁结吃什么药hcv8jop8ns5r.cn 圆脸适合什么刘海hcv9jop2ns1r.cn 莆田系是什么意思啊hcv9jop8ns2r.cn 怀孕吸烟对胎儿有什么影响hcv8jop1ns7r.cn 茶卡是什么意思hcv8jop7ns6r.cn
1983年出生是什么命hcv7jop7ns0r.cn 腹部超声检查什么huizhijixie.com 为什么出汗有酸臭味hcv9jop1ns3r.cn 边沿是什么意思qingzhougame.com 痤疮用什么药治最好效果最快hcv7jop7ns2r.cn
冰乙酸是什么huizhijixie.com 苹果为什么叫苹果hcv7jop6ns5r.cn 梦见大山是什么预兆hcv8jop0ns4r.cn sub是什么意思hcv9jop6ns0r.cn 花木兰代表什么生肖hcv9jop0ns3r.cn
百度