I have a very large undirected graph dataset in the form of .txt, which I converted to networkx graph. I need to extract a connected subgraph containing N nodes (and E edges if possible, but not necessary). How do I go about it? This is the code I wrote for finding largest connected subgraph :
def find_subgraph(graph):
connected_component_subgraphs = (graph.subgraph(c) for c in nx.connected_components(graph))
largest_subgraph = max(connected_component_subgraphs, key=len)
return largest_subgraph
The subgraph I want is somewhere in the middle of min and max subgraphs. Any help help will be appreciated.
Edit : It can be any N nodes, no specific nodes required