Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

Students also viewed these Databases questions

Question

3. The group answers the questions.

Answered: 1 week ago