David Milne - 2013-12-17

Hi Amir,

It looks like you are performing a breadth first search:

http://en.wikipedia.org/wiki/Breadth-first_search

A simple way to avoid loops is to keep a big HashSet of the category ids you have seen.
If you see a category a second time, you know that you do not need to visit any of its children.