have to construct a connected graph ( some of the vertices have to connect two or more edges) from a list of pseudorandom numbers. I have tried this but got errors. Any help would be highly appreciated.   import java.util.ArrayList; import java.util.List; import java.util.Random; public class MuddyTown { int weight; int m = 5; int d = 1; int k = 32; int s = 1; ArrayList randomList = new ArrayList<>(); //ArrayList randomList = new ArrayList<>(); //static ArrayList randomList; ArrayList connectedGraph = new ArrayList<>(); // Maximum number of vertices int V; //ArrayList[] adj; List> adjList; public MuddyTown() { V = randomList.size(); adjList = new ArrayList<>(V); for (int i = 0; i< V; i++) { adjList.add(new ArrayList<>()); } // for (int i = 0; i(V)); // } } ArrayList pseudoRandom() { for (int i = 0; i< 30; i++) { s = ( m * s + d) % k; randomList.add(s); } return randomList; } void addEdge(int x, int y) { adjList.get(x).add(y); } void createRandomGraph() { Random random = new Random(); // Add each vertex with its previous vertex for (int i = 0; i < randomList.size() -1; i++) { int currentVertex = randomList.get(i); addEdge(i, randomList.get(i + 1)); int index = random.nextInt(randomList.size()); weight = randomList.get(index); String line = weight + " " + currentVertex + " " + randomList.get(i + 1); connectedGraph.add(line); } // join 20 edges randomly for (int a = 0; a<20; a++) { int j = random.nextInt(randomList.size()); int k = random.nextInt(randomList.size()); addEdge(j, randomList.get(k)); int b = random.nextInt(randomList.size()); weight = randomList.get(b); String value = weight + "," + randomList.get(j) + "," + randomList.get(k); connectedGraph.add(value); } } public static void main(String[] args) { MuddyTown g = new MuddyTown(); g.pseudoRandom(); System.out.println("Size of random list: " + g.randomList.size()); for (int a: g.randomList ) { System.out.println("Random list: " + a); } g.createRandomGraph(); for (int i = 0; i< g.connectedGraph.size(); i++) { System.out.println(g.connectedGraph.get(i)); } } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I have to construct a connected graph ( some of the vertices have to connect two or more edges) from a list of pseudorandom numbers. I have tried this but got errors.

Any help would be highly appreciated.

 

import java.util.ArrayList; import java.util.List; import java.util.Random; public class MuddyTown { int weight; int m = 5; int d = 1; int k = 32; int s = 1; ArrayList<Integer> randomList = new ArrayList<>(); //ArrayList<Integer> randomList = new ArrayList<>(); //static ArrayList<Integer> randomList; ArrayList<String> connectedGraph = new ArrayList<>(); // Maximum number of vertices int V; //ArrayList<Integer>[] adj; List<List<Integer>> adjList; public MuddyTown() { V = randomList.size(); adjList = new ArrayList<>(V); for (int i = 0; i< V; i++) { adjList.add(new ArrayList<>()); } // for (int i = 0; i<V; i++) { // adjList.add(new ArrayList<>(V)); // } } ArrayList<Integer> pseudoRandom() { for (int i = 0; i< 30; i++) { s = ( m * s + d) % k; randomList.add(s); } return randomList; } void addEdge(int x, int y) { adjList.get(x).add(y); } void createRandomGraph() { Random random = new Random(); // Add each vertex with its previous vertex for (int i = 0; i < randomList.size() -1; i++) { int currentVertex = randomList.get(i); addEdge(i, randomList.get(i + 1)); int index = random.nextInt(randomList.size()); weight = randomList.get(index); String line = weight + " " + currentVertex + " " + randomList.get(i + 1); connectedGraph.add(line); } // join 20 edges randomly for (int a = 0; a<20; a++) { int j = random.nextInt(randomList.size()); int k = random.nextInt(randomList.size()); addEdge(j, randomList.get(k)); int b = random.nextInt(randomList.size()); weight = randomList.get(b); String value = weight + "," + randomList.get(j) + "," + randomList.get(k); connectedGraph.add(value); } } public static void main(String[] args) { MuddyTown g = new MuddyTown(); g.pseudoRandom(); System.out.println("Size of random list: " + g.randomList.size()); for (int a: g.randomList ) { System.out.println("Random list: " + a); } g.createRandomGraph(); for (int i = 0; i< g.connectedGraph.size(); i++) { System.out.println(g.connectedGraph.get(i)); } } }

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY