Question: I'm trying to write a function that makes a random undirected simple graph on python. def makegraph(n,p) it will take as input from the user

I'm trying to write a function that makes a random undirected simple graph on python.

def makegraph(n,p)

it will take as input from the user n nodes(vertices) and take p as input where p is probability between 0 and 1. The p will add edges randomly with a probabiliy of p.

and it will output a representation of the graph like

Print all adjacency lists with corresponding vertex:

0: [1, 2]

1: [2, 3]

2: [4]

3: [4, 5]

4: [5]

5: []

I tried using adjancy lists but have a hard time implementing the functions with it. Can someone please provide some code to point me in the right direction.

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!