From charlesreid1

No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
==Breadth-first search using queues==
==Breadth-first search using queues==


When doing BFS, use a queue.  
When doing BFS, use a queue. The pseudocode looks like this:
 
Add the root node to the queue.
 
While the queue is not empty:
 
remove item from queue,
 
perform action on item,
 
add children to queue.


<pre>
add root to queue
while queue not empty:
    remove next item from queue
    perform search action on item
    add children queue
</pre>


==Flags==
==Flags==


{{TreesFlag}}
{{TreesFlag}}
{{GraphsFlag}}


[[Category:Queues]]
[[Category:Trees]]
[[Category:Trees]]
[[Category:Binary Trees]]
[[Category:Graphs]]
[[Category:Traversal]]
[[Category:Traversal]]
[[Category:Algorithms]]
[[Category:Algorithms]]
[[Category:Queues]]

Latest revision as of 15:51, 7 September 2017

Breadth-first search using queues

When doing BFS, use a queue. The pseudocode looks like this:

add root to queue
while queue not empty:
    remove next item from queue
    perform search action on item
    add children queue

Flags