educative.io

How is it a BFS?

I can’t see how this relates to BFS. Can anyone explain both from the implementation and intuition perspective where is the BFS here?

Hi,

We can’t view it as BFS from an implementation point of view, but we can intuitively view it as BFS.
We start from an empty set and view it as the root of a tree. The subsets will be viewed as the nodes of the tree. We proceed to the next levels and on each level, we add a new element to all the nodes (i.e. subsets). Therefore, on each level, we process the whole level before going to the next level, which is the same approach as that of BFS.

4 Likes