Fix pseudocode formatting.

This commit is contained in:
Oleksii Trekhleb
2018-08-14 15:46:58 +03:00
parent b6ac765c99
commit b0c9057cdb
3 changed files with 291 additions and 257 deletions

View File

@@ -10,29 +10,27 @@ nodes first, before moving to the next level neighbors.
## Pseudocode
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
## Space and Time Complexity:
O(b<sup>d + 1</sup>)
```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