Question: Please help me implement my graph with this function. My graph is using n and p as inputs where n is number of vertices and

Please help me implement my graph with this function. My graph is using n and p as inputs where n is number of vertices and p is the probability of adding a new edge. I need to make a new function called check_component_size(graph) which takes as input an undirected simple graph returns a list containing the sizes of all connected components in the graph.

MY INPUT:

N = int(input("# of vertices:")) #taking number of vertices from user

P = float(input("probability of new edge:")) #take probability from user

edges = [] #initially edges list is empty adj = [[] for i in range(N)] #initially the adjancy list is as well empty

def makeGraph(N,P): #populating edges with all possible edge for i in range(N): for j in range(i+1,N): edges.append([i,j]) #shuffling the edges randomly random.shuffle(edges)

#total no of edges = n*(n-1)/2 and probabbility = p so #so numbe rof eges to take = p*n*(n-1)/2

no_of_edges = int(P*(N-1)*N/2)

for i in range(no_of_edges): adj[edges[i][0]].append(edges[i][1])#appending the vertices to corresponding edges points adj[edges[i][1]].append(edges[i][0]) #printing out the results

for i in range(N): print(i,":",adj[i])

MY OUTPUT:

enter the number of vertices:4 <== my input enter the probability:.25 <=== my input 0 : [3] 1 : [] 2 : [] 3 : [0]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!