Given a random simple graph of N nodes, N edges, and a uniform edge probability p, what is the expected size of the largest connected component?
- The only initial input parameter supplied is N, which represents the number of nodes in the graph
- The graph is simple, meaning that it is not allowed to contain any self-loops
- There are exactly N node pairings, ie. the edgelist is of the form
{(1,a), (2,b), (3,c), ..., (N,[next available letter of the alphabet])}
. The conditions are that a!=1, b!=2, c!=3 etc. but other than that, a,b,c,... can take any value from 1 to N inclusive - The node n forming an edge with some other node can be described by a uniform probability distribution
- Foreach such valid graph constructed of N nodes and N edges, find the size of the largest connected component S
- By connected component, this is defined as the largest cluster/group of nodes where each node in the connected component can reach to/is reachable from every other node in the same connected component
The question is: among all such valid graphs constructed, what is the expected value of S?
I would like to know of an efficient way to think about/analyze/solve this problem that can deal with N ranging from 2 to 50 inclusive. Some code to illustrate would be helpful to my understanding.
I wrote the following source codes to naively bruteforce the possibilities, hoping to find a pattern from there. Managed to get up to N = 9
with these:
Both attempt to generate all possible permutations according to the criteria specified in the problem, and then calculate S for each graph generated via BFS.
Output so far
As for the format, eg. for the line "N=4: {2:3,4:78} 106/27
", this means that there are 3 graphs with the size of the largest component = 2, and 78 graphs with the size of the largest component = 4, so the final answer = (3/(78+3))*2 + (78/(78+3))*4 = 106/27
.
N=2: {2:1} 2/1
N=3: {3:8} 3/1
N=4: {2:3,4:78} 106/27
N=5: {3:80,5:944} 155/32
N=6: {2:15,3:640,4:1170,6:13800} 17886/3125
N=7: {3:840,4:21840,5:19824,7:237432} 38563/5832
N=8: {2:105,3:17920,4:229320,5:422912,6:386400,8:4708144} 6152766/823543
N=9: {3:153440,4:786240,5:9634464,6:9273600,7:8547552,9:105822432} 17494593/2097152
edit: Just discovered this OEIS sequence #A000435 gives the answers (formula/listing up to N=18) for the number of graphs with N nodes and largest size component = N. This is exactly coincidental with my bruteforce output, eg. for N=9, there are 105822432 graphs with the largest size of connected component = 9. Not sure if this helps - one of the formulas given there to derive this for larger N is a(n) = (n-1)! * Sum (n^k/k!, k=0..n-2)
Python implementation
Example for N = 4
:
There are a total of 81 possible edge assignments for 4 nodes (1-based indexed from 1 to N).
The format for the sample output below is: ((1, 2), (2, 1), (3, 1), (4, 1)): 4
means that there are edges between nodes 1 and 2, nodes 2 and 1, nodes 3 and 1, and nodes 4 and 1. Assume the edges are undirected/bidirectional. For such a graph, there is only a single connected component of all 4 nodes {1,2,3,4}, so the size of the largest (only) connected component is 4.
After generating this list, expected value of S can be computed via (fraction of all 81 instances where
S== 4) * 4 + (fraction of all 81 instances where
S== 2) * 2 =
106/27 - since the only values S takes are 2,4.
{((1, 2), (2, 1), (3, 1), (4, 1)): 4,
((1, 2), (2, 1), (3, 1), (4, 2)): 4,
((1, 2), (2, 1), (3, 1), (4, 3)): 4,
((1, 2), (2, 1), (3, 2), (4, 1)): 4,
((1, 2), (2, 1), (3, 2), (4, 2)): 4,
((1, 2), (2, 1), (3, 2), (4, 3)): 4,
((1, 2), (2, 1), (3, 4), (4, 1)): 4,
((1, 2), (2, 1), (3, 4), (4, 2)): 4,
((1, 2), (2, 1), (3, 4), (4, 3)): 2,
((1, 2), (2, 3), (3, 1), (4, 1)): 4,
((1, 2), (2, 3), (3, 1), (4, 2)): 4,
((1, 2), (2, 3), (3, 1), (4, 3)): 4,
((1, 2), (2, 3), (3, 2), (4, 1)): 4,
((1, 2), (2, 3), (3, 2), (4, 2)): 4,
((1, 2), (2, 3), (3, 2), (4, 3)): 4,
((1, 2), (2, 3), (3, 4), (4, 1)): 4,
((1, 2), (2, 3), (3, 4), (4, 2)): 4,
((1, 2), (2, 3), (3, 4), (4, 3)): 4,
((1, 2), (2, 4), (3, 1), (4, 1)): 4,
((1, 2), (2, 4), (3, 1), (4, 2)): 4,
((1, 2), (2, 4), (3, 1), (4, 3)): 4,
((1, 2), (2, 4), (3, 2), (4, 1)): 4,
((1, 2), (2, 4), (3, 2), (4, 2)): 4,
((1, 2), (2, 4), (3, 2), (4, 3)): 4,
((1, 2), (2, 4), (3, 4), (4, 1)): 4,
((1, 2), (2, 4), (3, 4), (4, 2)): 4,
((1, 2), (2, 4), (3, 4), (4, 3)): 4,
((1, 3), (2, 1), (3, 1), (4, 1)): 4,
((1, 3), (2, 1), (3, 1), (4, 2)): 4,
((1, 3), (2, 1), (3, 1), (4, 3)): 4,
((1, 3), (2, 1), (3, 2), (4, 1)): 4,
((1, 3), (2, 1), (3, 2), (4, 2)): 4,
((1, 3), (2, 1), (3, 2), (4, 3)): 4,
((1, 3), (2, 1), (3, 4), (4, 1)): 4,
((1, 3), (2, 1), (3, 4), (4, 2)): 4,
((1, 3), (2, 1), (3, 4), (4, 3)): 4,
((1, 3), (2, 3), (3, 1), (4, 1)): 4,
((1, 3), (2, 3), (3, 1), (4, 2)): 4,
((1, 3), (2, 3), (3, 1), (4, 3)): 4,
((1, 3), (2, 3), (3, 2), (4, 1)): 4,
((1, 3), (2, 3), (3, 2), (4, 2)): 4,
((1, 3), (2, 3), (3, 2), (4, 3)): 4,
((1, 3), (2, 3), (3, 4), (4, 1)): 4,
((1, 3), (2, 3), (3, 4), (4, 2)): 4,
((1, 3), (2, 3), (3, 4), (4, 3)): 4,
((1, 3), (2, 4), (3, 1), (4, 1)): 4,
((1, 3), (2, 4), (3, 1), (4, 2)): 2,
((1, 3), (2, 4), (3, 1), (4, 3)): 4,
((1, 3), (2, 4), (3, 2), (4, 1)): 4,
((1, 3), (2, 4), (3, 2), (4, 2)): 4,
((1, 3), (2, 4), (3, 2), (4, 3)): 4,
((1, 3), (2, 4), (3, 4), (4, 1)): 4,
((1, 3), (2, 4), (3, 4), (4, 2)): 4,
((1, 3), (2, 4), (3, 4), (4, 3)): 4,
((1, 4), (2, 1), (3, 1), (4, 1)): 4,
((1, 4), (2, 1), (3, 1), (4, 2)): 4,
((1, 4), (2, 1), (3, 1), (4, 3)): 4,
((1, 4), (2, 1), (3, 2), (4, 1)): 4,
((1, 4), (2, 1), (3, 2), (4, 2)): 4,
((1, 4), (2, 1), (3, 2), (4, 3)): 4,
((1, 4), (2, 1), (3, 4), (4, 1)): 4,
((1, 4), (2, 1), (3, 4), (4, 2)): 4,
((1, 4), (2, 1), (3, 4), (4, 3)): 4,
((1, 4), (2, 3), (3, 1), (4, 1)): 4,
((1, 4), (2, 3), (3, 1), (4, 2)): 4,
((1, 4), (2, 3), (3, 1), (4, 3)): 4,
((1, 4), (2, 3), (3, 2), (4, 1)): 2,
((1, 4), (2, 3), (3, 2), (4, 2)): 4,
((1, 4), (2, 3), (3, 2), (4, 3)): 4,
((1, 4), (2, 3), (3, 4), (4, 1)): 4,
((1, 4), (2, 3), (3, 4), (4, 2)): 4,
((1, 4), (2, 3), (3, 4), (4, 3)): 4,
((1, 4), (2, 4), (3, 1), (4, 1)): 4,
((1, 4), (2, 4), (3, 1), (4, 2)): 4,
((1, 4), (2, 4), (3, 1), (4, 3)): 4,
((1, 4), (2, 4), (3, 2), (4, 1)): 4,
((1, 4), (2, 4), (3, 2), (4, 2)): 4,
((1, 4), (2, 4), (3, 2), (4, 3)): 4,
((1, 4), (2, 4), (3, 4), (4, 1)): 4,
((1, 4), (2, 4), (3, 4), (4, 2)): 4,
((1, 4), (2, 4), (3, 4), (4, 3)): 4}