mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2026-03-13 08:51:02 +08:00
Merge branches 'fourier' and 'master' of https://github.com/trekhleb/javascript-algorithms into fourier
This commit is contained in:
@@ -8,6 +8,30 @@ nodes first, before moving to the next level neighbors.
|
||||
|
||||

|
||||
|
||||
## Pseudocode
|
||||
|
||||
```text
|
||||
BFS(root)
|
||||
Pre: root is the node of the BST
|
||||
Post: the nodes in the BST have been visited in breadth first order
|
||||
q ← queue
|
||||
while root = ø
|
||||
yield root.value
|
||||
if root.left = ø
|
||||
q.enqueue(root.left)
|
||||
end if
|
||||
if root.right = ø
|
||||
q.enqueue(root.right)
|
||||
end if
|
||||
if !q.isEmpty()
|
||||
root ← q.dequeue()
|
||||
else
|
||||
root ← ø
|
||||
end if
|
||||
end while
|
||||
end BFS
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
- [Wikipedia](https://en.wikipedia.org/wiki/Breadth-first_search)
|
||||
|
||||
Reference in New Issue
Block a user