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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started