Skip to content

Tag: graph-theory

Algorithm for Connected Components of Graph

I am looking for the most efficient algorithm in order to find both the number of connected components in a network, and the number of nodes for each connected component. Example: Given the following inputs: I would receive the following output: This is what I have so far: I have found a way to iterate throug…

How to connect two nodes if they are disconnected

I use a python NetworkX graph. How to check if 2 nodes are disconnected and then get a new version of the graph where these 2 nodes are connected. The difference between 2 graphs should have min edit distance (Levenshtein distance) Before and after for nodes=[1,2]: | Answer you can also have a condition to ch…

Fetch connected nodes in a NetworkX graph

Straightforward question: I would like to retrieve all the nodes connected to a given node within a NetworkX graph in order to create a subgraph. In the example shown below, I just want to extract all the nodes inside the circle, given the name of one of any one of them. I’ve tried the following recursi…