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