How to get subgraph S comprised of nodes with multiple edges of a multigraph M?

169 Views Asked by At

Given a graph M, I would like to get the subgraph S which contains only the nodes of M which have two or more edges. I am mainly looking to see if there is an already-known algorithm which does this.

For anyone looking at this question in the future or confused by this question, my graph could be represented by a dictionary like so, where each key is a node and the value is how many edges connect the nodes:

{
A: {B: 2, C: 1, D: 3}
B: {A: 2, D: 2}
C: {A: 1}
D: {A: 3, B: 2, E: 1}
E: {D: 1}
}

The subgraph I would like to get is:

{
A: {B: 2, D: 3}
B: {A: 2, D: 2}
D: {A: 3, B: 2}
}
1

There are 1 best solutions below

0
On BEST ANSWER

From what it sounds like, you are looking for an algorithm to find the $2$-core of a graph. The $k$-core of a graph is the (unique) maximal subgraph that had minimum degree $k$. There are algorithms to find the $k$-core of a graph. For more information about cores and the algorithms to find them, here is the wikipedia entry that discusses $k$-cores and includes an algorithm to find the $k$-core: https://en.m.wikipedia.org/wiki/Degeneracy_(graph_theory)