educative.io

Educative

Why this is said as BFS?

Can someone explain how this problem pattern is being solved by BFS?
I understand these BFS/DFS concepts are applicable to trees/graphs, since this problem is using arrays that are being traversed linearly, I couldn’t figure out how this comes under BFS pattern.

Thanks.

Hi @Debashis_Das
We appreciate you reaching out to us. With the BFS graph technique, we start at a source node and make our way across the graph layer by layer while examining the neighboring nodes. Here, in this case, we can assume that our source node is the first element of the array. When going layer by layer, with each layer containing one element, we then examine how many subsets are available from that particular element.


I hope this helps. Happy Learning :slight_smile: