How do I check connection between 2 nodes in an undirected graph?

So I need a boolean method that requires 3 parameters (graph, node i, node j). This method should search and find if two nodes are somehow connected in an undirected graph. It should return true, if nodes i and j are connected in any way, false otherwise


Do these Graph and Node types exist in your program ?
If so, can you give more details especially on their structure?
How do you determine 2 graphs are connected in an undirected graph?


This sounds like a problem from a Data Structures and Algorithms class (or possibly an interview question). In either case, you need more information about the API and/or data structures for the Graph and Node classes.

In general, this is a pretty standard sounding graph-processing problem (checking for connected components). You can do any of a number of different search patterns like BFS and DFS to exhaustively search all nodes connected to the first node and return true early if you find the second node (otherwise you return false if you have searched all of the nodes and did not find the second node).