Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I'm a student an I see the BFS Algorithm for graph exploration. I see the DFS algorithm too and this one is easily thinkable in a recursive mode. But is it possible for the BFS?


share|improve this question

1 Answer 1

up vote 4 down vote accepted

You can always rewrite any iterative algorithm to a tail-recursive one -- in this case, by passing the entire work list as a parameter to a recursive call instead of jumping back to the top of the loop.

However, I don't think doing so would be particularly enlightening for breadth-first, except if you have to implement it in a language that has recursion but no explicit iteration constructs.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.