In java generate a random graph using the following process: Given a graph with n nodes, and a number p chosen between 0 and 1,
In java generate a random graph using the following process: Given a graph with n nodes, and a number p chosen between 0 and 1, a link between two nodes is going to be generated if a uniform random draw between 0 and 1 is less than the number p.
choose you graph implementation allowing to build such graphs(you should be able to generate graphs up to 1000 nodes).
Implement a method on your graph using breadth first search to check if all nodes are reachable from each other. Then implement the following experiment for n being 100, 200, 300, 400, 500, and for each value of n, for p equal to .25, .5, .75:
Generate 1000 random graphs for n and p, and countre connected using the above.
This is what I have so far.
import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Queue; import java.util.Random; public class Graph2 { private static int numberOfNodes; private boolean[][] adjacencyMatrix; private static int connectedCount = 0; private static int connected; //constructor Graph2(int n0) { Graph2.numberOfNodes = n0; this.adjacencyMatrix = new boolean[numberOfNodes][numberOfNodes]; } List outEdges(int node1) { List edges = new ArrayList(); for (int node2 = 0; node2 < numberOfNodes; node2++) if (adjacencyMatrix[node1][node2]){ edges.add(node2); } return edges; } //method to generate random graphs public static Graph2> createRandomGraph(int nodeCount, float p, int graphIndex) { Graph2> graph = new Graph2
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