> #Weiji Zheng, Assignment 18, 11/22/2020 ; > #OK TO POST HOMEWORK ; > ; > #Q1 ; > #Generalize procedure NuConG(N) of M18.txt to write a procedure NuKcomponentsGraphs(N,K) > # > #that inputs a positive integer N and another positive integer K and outputs the first N terms of the sequence enumerating the number of labeled graphs on n vertices with Exactly K componets. Make sure that NuKComponentsGraphs(N,1) equals NuConG(N) for N ¡Ü 6 > #Hint: Of course, you first need to write a procedure AllKcomponentsGraphs(n,K) by tweaking procedure AllConGraphs(n) and change the line nops(CCs(s))=1 to nops(CCs(s))=k > > #Are the following sequences in the OEIS? If yes, what are the A-numbers NuConGgen(5,2), NuConGgen(5,3) ; > ; > #AllKcomponentsGraphs(n,K) > AllKConGraphs:=proc(n,K) local s,S: > S:={}; > > for s in AllGraphs(n) do > if nops(CCs(s))=K then > S:= S union {s} > fi: > od: > S: > end: > ; > #NuKcomponentsGraphs(N,K) ; > NuKcomponentsGraphs:=proc(n,K) local nn:[seq(nops(AllKConGraphs(nn,K)),nn=1..n)]:end: > ; > NuConG(4): [1, 1, 4, 38] ; > NuKcomponentsGraphs(4,1) [1, 1, 4, 38] ; > ; > NuKcomponentsGraphs(5,2) [0, 1, 3, 19, 230] ; > #A323875 ; > ; > NuKcomponentsGraphs(5,3) [0, 0, 1, 6, 55] ; > #A323876 ; > ; > #Q2 ; > #Using procedures RandGr(n,K) and CCs(G), in M18.txt write a procedure AveNuCC(n,K,M) that generates M random graphs on n vertices with K edges, and for each of them finds the number of components and take the average over these M random graphs. Run it several times with n=30 and M=1000 to check that you get close answers. If not what M would give such agreement? ; > ; > AveNuCC:=proc(n,K,M) local a,total,res: > > total := 0: > > for a from 1 to M do > total := total + nops(CCs(RandGr(n, K))): > od: > res := total/M: > res: > end: > ; > ; > #Q3 ; > #Using the above,say, write a procedure EstimateCutOff(n,M)that inputs a positive integer n and outputs an estimate for the "threshold" for K, when most graphs with K edges start to be connected (say when the average number of connected componets is less than 1.05) > ; > ; > ; > ; > ; > ; > ; > ; > ; > ; > ; > ; > ; > ; > ; > ; > ; > ; > ; > ; > ;