File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
src/algorithms/tree/breadth-first-search Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,32 @@ nodes first, before moving to the next level neighbors.
88
99![ Algorithm Visualization] ( https://upload.wikimedia.org/wikipedia/commons/5/5d/Breadth-First-Search-Algorithm.gif )
1010
11+ ## Pseudocode
12+
13+ BFS(root)
14+ Pre: root is the node of the BST
15+ Post: the nodes in the BST have been visited in breadth first order
16+ q ← queue
17+ while root = ø
18+ yield root.value
19+ if root.left = ø
20+ q.enqueue(root.left)
21+ end if
22+ if root.right = ø
23+ q.enqueue(root.right)
24+ end if
25+ if !q.isEmpty()
26+ root ← q.dequeue()
27+ else
28+ root ← ø
29+ end if
30+ end while
31+ end BFS
32+
33+ ## Space and Time Complexity:
34+
35+ O(b<sup >d + 1</sup >)
36+
1137## References
1238
1339- [ Wikipedia] ( https://en.wikipedia.org/wiki/Breadth-first_search )
You can’t perform that action at this time.
0 commit comments