What if my graph is not connected?


See here i tried to traverse through my visited map , but it is not printing disconnected part. Which is K & L .

@raj.verma5454 its is not traversing throught that part because there is no key for K and L. first initalised it with that key then it will definiately traverse though it.
If you didnt get what i am saying here just try to print Visited map after traversal you will get it.

I have one more doubt , If there is no key for K and L , see in this code https://ide.codingblocks.com/s/232050. There is also no key for all of the vertices still we are checking the if condition , see line no 39. Then how it is working?

@raj.verma5454 in previous code the graph is not fully connected and when you are travesing it. It mark all visited node there is no memory for disconnected part of the graph.

But in this code all node is connected means you can reach from every node to every other node but not in previous one.