[algorithm] Performing Breadth First Search recursively