How can I determine whether selected nodes on a graph are directly connected?
I think, I need to calculate paths for each selected node to all of the other selected nodes. Then, when I have the path, I have to check whether path contains only selected nodes.
In the code, all I have is a notion of nodes and edges, like this:
const nodes = [
{ id: "A" },
{ id: "B" },
{ id: "C" },
{ id: "D" },
{ id: "E" },
{ id: "F" },
];
const edges = [
{ target: "A", source: "B" },
{ target: "B", source: "C" },
{ target: "C", source: "D" },
{ target: "D", source: "E" },
{ target: "E", source: "F" },
];
Examples:
Good selection:
Bad selection:
Is there some algorithm for checking that? Are you aware of some npm packages in case of JavaScript?

