views:

739

answers:

2

as i rememeber and checked, that the usual way for traversing a tree or crawling the web breadth first (BFS) is by using a queue. Is there actually a way to implement it not using a queue?

A: 

With recursion. But the queue is in the stack...

eKek0
is there like a simple pseudo code some where that can implement BFS using recursion?
動靜能量
I wonder about this too. How do you want to efficiently replace a queue by using the callstack?
Lucero
+2  A: 

You really should be using a queue, as its easier to implement. Also, a queue allows for multiple machines to work together (one queues site while another pops sites off of the queue to traverse).

The only other way I see to do this is by using recursion (much more difficult, and uses only marginally either more or less memory).

AlbertoPL
how do you use a stack to simulate a queue?
動靜能量
see http://stackoverflow.com/questions/69192/using-stack-as-queue . Essentially, you can use two stacks.
AlbertoPL