Breadth First Search

Template:

qs1

If a layer traversal is needed, add a “for” loop. (Attention that queue.size will change).

If in a graph, we need a hash set to store the statue of node ( visited or not), and check set.contains(child) before offerring it into queue.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s