BFT: Difference between revisions
From charlesreid1
(Created page with "Breadth-first traversal: same idea as breadth-first search BFS, except for traversing the tree. So, instead of searching for something in the tree, you're performing a vis...") |
No edit summary |
||
| Line 1: | Line 1: | ||
==Breadth-first traversal using queues== | |||
Breadth-first traversal: same idea as breadth-first search [[BFS]], except for traversing the tree. So, instead of searching for something in the tree, you're performing a visit action. | Breadth-first traversal: same idea as breadth-first search [[BFS]], except for traversing the tree. So, instead of searching for something in the tree, you're performing a visit action. | ||
When doing BFT, use a queue. The pseudocode looks like this: | |||
<pre> | |||
add root to queue | |||
while queue not empty: | |||
remove next item from queue | |||
perform visit action on item | |||
add children queue | |||
</pre> | |||
[[Category:Traversal]] | |||
[[Category:BFT]] | |||
Revision as of 20:12, 11 June 2017
Breadth-first traversal using queues
Breadth-first traversal: same idea as breadth-first search BFS, except for traversing the tree. So, instead of searching for something in the tree, you're performing a visit action.
When doing BFT, use a queue. The pseudocode looks like this:
add root to queue
while queue not empty:
remove next item from queue
perform visit action on item
add children queue