Problem

Random grid graphs.Write a EuclideanGraph client RandomGridGraph that generates random gra...

Random grid graphs.Write a EuclideanGraph client RandomGridGraph that generates random graphs by connecting vertices arranged in a grid to their neighbors (see exercise 1.5.18). Augment your program to add Rextra random edges. For large R, shrink the grid so that the total number of edges remains about 2 V. Add an option such that an extra edge goes from a vertex s to a vertex t with probability inversely proportional to the Euclidean distance between s and t.

Exercise: 1.5.18

Random grid generator.Write a program RandomGrid that takes an int value N from the command line, generates all the connections in an N-by-N grid, puts them in random order, randomly orients them (so that p q and q p are equally likely to occur), and prints the result to standard output. To randomly order the connections, use a RandomBag (see exercise 1.3.34 on page 167). To encapsulate p and q in a single object, use the Connection nested class shown below. Package your program as two static methods: generate(), which takes N as argument and returns an array of connections, and mainO, which takes N from the command line, calls generate(), and iterates through the returned array to print the connections.

Exercise 1.3.34

Random bag.A random bagstores a collection of items and supports the following API:

Write a class RandomBag that implements this API. Note that this API is the same as for Bag, except for the adjective random,which indicates that the iteration should provide the items in randomorder (all N! permutations equally likely, for each iterator). Hint: Put the items in an array and randomize their order in the iterator’s constructor.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search