BFT another short approach


Please tell me if this approach is good to go for Breadth First Traversal.
This approach doesn’t use Pair class.
It’s a tweaked version of approach that is shown in video.

Approach :
First made an Arraylist of keyset of all vertices.and iterated every element one by one.

In Iteration :
made processed HashSet and Queue and added current element to Queue and also in HashSet

then while !queue.empty :
made ArrayList nbrs of removed element neighbours but not included in HashSet and while iterating each neighbour(if its not present in processed), printed nbr
and added nbr in queue as well as in HashSet

It worked fine with the large graph that mam made in previous video.

Note : It’s the tweaked version of actual method that is shown in video. Its more like level order traversal thats done in trees

The graph that I’m talking about :

The code Worked fine for this graph and gave output :

it seems fine.
but when u have to find the cost as well path then u have to form a helper class

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.