All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Hire a Tutor
AI Study Help
New
Search
Search
Sign In
Register
study help
Computer science
algorithm design
introduction to programming
Questions and Answers of
Introduction To Programming
In the classic Erdös-Renyi random graph model, we build a random graph on \(V\) vertices by including each possible edge with probability \(p\), independently of the other edges. Compose a Graph
Develop a graph model for percolation, and write a Graph client that performs the same computation as Percolation (ProgrAm 2.4.5). Estimate the percolation threshold for triangular, square, and
Write a Graph client AllPaths whose constructor takes a Graph as argument and supports operations to count or print all simple paths between two given vertices \(\mathrm{s}\) and \(\mathrm{t}\) in
A Picture is a two-dimensional array of Co Tor values (see SECTION 3.1) that represent pixels. A blob is a collection of neighboring pixels of the same color. Write a Graph client whose constructor
As mentioned in the text, an alternative way to compute Kevin Bacon numbers is to build a graph where there is a vertex for each performer (but not for each movie), and where two performers are
Implement a test client main() for SmallWorld (Program 4.5.5) that produces the output given in the text. Your program should take the name of a graph file and a delimiter as command-line arguments;
Add to SmallWorld (Program 4.5.5) the function is SmallWorld() that takes a graph as an argument and returns true if the graph exhibits the small-world phenomenon (as defined by the specific
Add an overloaded function clusterCoefficient() that takes an integer argument \(k\) to Sma17Wor7d (Program 4.5.5) so that it computes a local cluster coefficient for the graph based on the total
Create a version of Graph from the previous exercise to support bipartite graphs (graphs whose edges all connect a vertex of one generic comparable type to a vertex of another generic comparable
Order statistics. Add to BST a method select() that takes an integer argument \(k\) and returns the \(k\) th smallest key in the BST. Maintain subtree sizes in each node (see EXERCISE 4.4.29). The
Add to BST a method random() that returns a random key. Maintain subtree sizes in each node (see EXERCISE 4.4.29). The running time should be proportional to the height of the tree.
Inverted index of web. Extend the previous exercise so that it supports multi-word queries. In this case, output the list of web pages that contain at least one occurrence of each of the query words.
Repeat the previous exercise but uses a circular linked list. In a circular linked list, each node points to its successor, and the last node in the list points to the first node (instead of nu11, as
Nonrecursive mergesort. Given \(n\) strings, create \(n\) queues, each containing one of the strings. Create a queue of the \(n\) queues. Then, repeatedly apply the sorted merging operation from the
Random iterator. Write an iterator for RandomQueue from the previous exercise that returns the items in random order. Different iterators should return the items in different random orders. Note:
Modify MM1Queue (Program 4.3.7) to make a program MD1Queue that simulates a queue for which the service times are fixed (deterministic) at rate of \(\mu\). Verify Little's law for this model.
Write an iterable Stack client that has a static method copy() that takes a stack of strings as its argument and returns a copy of the stack. See EXERCISE 4.3.48 for an alternative approach.
Write a program EvaluatePostfix that takes a postfix expression from standard input, evaluates it, and prints the value. (Piping the output of your program from the previous exercise to this program
Draw a memory-usage diagram in the style of the diagrams in SeCtion 4.1 for the three-node example used to introduce linked lists in this section.
Add a method size() to both Stack (Program 4.3.4) and Queue (Program 4.3.6) that returns the number of items in the collection. Hint: Make sure that your method takes constant time by maintaining an
Add a method peek() to Stack (Program 4.3.4) that returns the most recently inserted item on the stack (without removing it).
What does the following code fragment do to the queue queue?![](https://cdn.mathpix.com/cropped/2024_01_29_11ead169f0ea3f5ee619g-26.jpg?height=219&width=803&top_left_y=1105&top_left_x=332)
Add a method isFu11() to ArrayStackOfStrings (Program 4.3.1) that returns true if the stack size equals the array capacity. Modify push() to throw an exception if it is called when the stack is full.
Percolation threshold. Write a Percolation (Program 2.4.1) client that uses bisection search to estimate the percolation threshold value.
Implied volatility. Typically the volatility \(\sigma\) is the unknown value in the Black-Scholes formula (see EXERCISE 2.1.28). Write a program that reads \(s, x, r, t\), and the current price of
Discrete distribution. Design a fast algorithm to repeatedly generate numbers from the discrete distribution: Given an array \(\mathrm{a}[]\) of non-negative real numbers that sum to 1 , the goal is
Write a recursive program that sorts an array of Comparable objects by using, as a subroutine, the partitioning algorithm described in the previous exercise: First, pick a random element \(v\) as the
Mode. Add to StdStats (Program 2.2.4) a method mode() that computes in linearithmic time the mode (value that occurs most frequently) of an array of \(n\) integers. Hint: Reduce to sorting.
Median. Add to StdStats (Program 2.2.4) a method median() that computes in linearithmic time the median of an array of \(n\) integers. Hint: Reduce to sorting.
Analyze mergesort for the case when \(n\) is not a power of 2 .
Develope a nonrecursive version of mergesort (Program 4.2.6). For simplicity, assume that the number of items \(n\) is a power of 2. Extra credit: Make your program work even if \(n\) is not a power
Add methods to Insertion (Program 4.2.4) and Merge (Program 4.2.6) to support sorting subarrays.
Modify Counter (Program 3.3.2) so that it implements the Comparable interface (comparing the objects by frequency count).
Modify Time (Exercise 3.3.21) so that it implements the Comparab7e interface (comparing the times chronologically).
Modify StockAccount (Program 3.2.8) so that it implements the Comparable interface (comparing the stock accounts by name). Hint: Use the compareTo () method from the String data type for the heavy
Implement a more general version of Program 4.2.2 that applies bisection search to any monotonically increasing function. Use functional programming, in the same style as the numerical integration
Add code to Insertion to produce the trace given in the text.
Modify BinarySearch (Program 4.2.3) so that if the search key is in the array, it returns the smallest index \(i\) for which \(a[i]\) is equal to key, and otherwise returns \(-i\), where \(i\) is the
Develop a nonrecursive version of BinarySearch (Program 4.2.3).
Develop an implementation of Questions (Program 4.2.1) that takes the maximum number \(n\) as a command-line argument. Prove that your implementation is correct.
Write a version of PrimeSieve (Program 1.4.3) that uses a byte array instead of a boolean array and uses all the bits in each byte, thereby increasing the largest value of \(n\) that it can handle by
Estimate, as a function of the number of documents \(n\) and the dimension \(d\), the amount of memory used by CompareDocuments (Program 3.3.5).
Estimate, as a function of the grid size \(n\), the amount of space used by PercolationVisua7izer (Program 2.4.3) with the vertical percolation detection (Program 2.4.2). Extra credit: Answer the
Apply the scientific method to develop and validate a hypothesis about the order of growth of the running time of Markov (PROGRAM 1.6.3), as a function of the command-line arguments trials and \(n\).
Apply the scientific method to develop and validate a hypothesis about the order of growth of the running time of the col1ect() method in Coupon (Program 2.1.3), as a function of the argument n.
Implement the static method printTriples() for ThreeSum (Program 4.1.1), which prints to standard output all of the triples that sum to zero.
What should the direction() method in Vector (PROGRAM 3.3.3) do if invoked with the all zero vector?
Is there a relationship between the Vector (PROGRAM 3.3.3) data type defined in this section and Java’s java.util.Vector data type?
The instance variables in Complex are private, but when I am executing the method plus() for a Complex object with a.plus(b), I can access not only a’s instance variables but also b’s.
Write a function hash() that takes as its argument a \(k\)-gram (string of length \(k\) ) whose characters are all \(\mathrm{A}, \mathrm{C}, \mathrm{G}\), or \(\mathrm{T}\) and returns an int value
A vector field associates a vector with every point in a Euclidean space. Write a version of Potential (EXERCISE 3.2.23) that takes as input a grid size \(n\), computes the Vector value of the
Develop an implementation of Java's java.uti1. Date API that is immutable and therefore corrects the defects of the previous exercise.
Develop a data type to store the genome of an organism. Biologists often abstract the genome to a sequence of nucleotides (A, C, G, or T). The data type should support the methods addNucleotide(char
Add code to Counter (Program 3.3.2) to throw an I17ega1ArgumentException if the client tries to construct a Counter object using a negative value for \(\max\).
Use assertions and exceptions to develop an implementation of Rationa1 (see EXERCISE 3.2.7) that is immune to overflow.
Describe the behavior of the method calls \(x \cdot \operatorname{add}(y)\) and \(y \cdot \operatorname{add}(x)\) in Vector (Program 3.3.3) if \(x\) corresponds to the vector \((1,2,3)\) and \(y\)
Override the equals() and hashCode() methods for Vector (Program 3.3.3) so that two Vector objects are equal if they have the same length and the corresponding coordinates are equal.
Override the equals() method for Charge (Program 3.2.6) so that two Charge objects are equal if they have identical position and charge value. Override the hashCode() method using the Objects.hash()
Implement the Vector2D data type from the previous exercise using one Complex value as the only instance variable.
If you know your physics, develop an alternate implementation for your data type from the previous exercise based on using the momentum \(\left(p_{x}, p_{y}, p_{z}\right)\) as an instance variable.
Create a data type for a three-dimensional particle with position \(\left(r_{x}, r_{y}, r_{z}\right)\), mass \((m)\), and velocity \(\left(v_{x}, v_{y}, v_{z}\right)\). Include a method to return its
Develop an implementation of Histogram (Program 3.2.3) that uses Counter (Program 3.3.2).
The Julia set for a given complex number \(c\) is a set of points related to the Mandelbrot function. Instead of fixing \(z\) and varying \(c\), we fix \(c\) and vary \(z\). Those points \(z\) for
Dragon curves. Write a recursive Turt1e client Dragon that draws dragon curves (see EXERCISE 1.2.35 and EXERCISE 1.5.9). % java Dragon 15
Modify Charge (Program} 3.2.1) so that the charge value \(q\) is not finat, and add a method increaseCharge() that takes a double argument and adds the given value to the charge. Then, write a client
Implement the valueOf() and save() methods for StockAccount (Program 3.2.8).
Modify the toString() method in Comp1ex (Program 3.2.6) so that it prints complex numbers in the traditional format. For example, it should print the value \(3-i\) as \(3-i\) instead of \(3.0+-1.0
Develop a version of Hi stogram that uses Draw, so that a client can create multiple histograms. Add to the display a red vertical line showing the sample mean and blue vertical lines at a distance
Use Stopwatch to compare the cost of computing harmonic numbers with a for loop (see Program 1.3.5) as opposed to using the recursive method given in Section 2.3.
Write a client for your Interval class from the previous exercise that takes an integer command-line argument \(n\), reads \(n\) intervals (each defined by a pair of doubTe values) from standard
Implement a data type Rational for rational numbers that supports addition, subtraction, multiplication, and division.Use Euclid.gcd() (Program 2.3.1) to ensure that the numerator and the denominator
Add code to your test client from the previous exercise code to compute the average number of rectangles that intersect a given rectangle.
Swirl filter. Creating a swirl effect is similar to rotation, except that the angle changes as a function of distance to the center of the image. Use the same formulas as in the previous exercise,
Write a program Merge that takes a delimiter string followed by an arbitrary number of file names as command-line arguments; concatenates the corresponding lines of each file, separated by the
The example file DJIA.csv used for Split (PROGRAM 3.1.9) lists the date, high price, volume, and low price of the Dow Jones stock market average for every day since records have been kept. Download
Modify StockQuote (PROGRAM 3.1.8) to take multiple symbols on the command line.
Write a version of PotentialGene (PROGRAM 3.1.1) that finds all potential genes contained as substrings within a long DNA string. Add a command-line argument to allow the user to specify the minimum
Write a test client for PotentialGene (PROGRAM 3.1.1) that takes a string as a command-line argument and reports whether it is a potential gene.
Write a program to check whether an ISBN number is valid (see EXERCISE 1.3.35), taking into account that an ISBN number can have hyphens inserted at arbitrary places.
Modify ATbersSquares (Program 3.1.2) to take nine command-line arguments that specify three colors and then draws the six squares showing all the Albers squares with the large square in each color
Percolation in three dimensions. Implement a class Percolation3D and a class BooleanMatrix3D (for I/O and random generation) to study percolation in three-dimensional cubes, generalizing the
Fast percolation test. Modify the recursive flow() method in PROGRAM 2.4.5 so that it returns as soon as it finds a site on the bottom row (and fills no more sites). Hint: Use an argument done that
Sierpinski triangles. Write a recursive program to draw Sierpinski triangles (see PROGRAM 2.2.3). As with Htree, use a command-line argument to control the depth of the recursion. order 3 Sierpinski
Gray code. Modify Beckett (PROGRAM 2.3.3) to print the Gray code (not just the sequence of bit positions that change).
Combinations of size \(k\). Modify Combinations from the previous exercise so that it takes two integer command-line arguments \(n\) and \(k\), and prints all \(C(n, k)=n ! /(k !(n-k) !)\)
Permutations of size \(k\). Modify Permutations from the previous exercise so that it takes two command-line arguments \(n\) and \(k\), and prints all \(P(n, k)=\) \(n ! /(n-k)\) ! permutations that
Binary representation. Write a program that takes a positive integer \(n\) (in decimal) as a command-line argument and prints its binary representation. Recall, in Program 1.3.7, that we used the
Animated plots. Write a program that takes a command-line argument \(m\) and produces a bar graph of the \(m\) most recent double values on standard input. Use the same animation technique that we
Music library. Develop a library based on the functions in PlayThatTune (Program 2.1.4) that you can use to write client programs to create and manipulate songs.
IFS matrix implementation. Write a version of IFS that uses the static method multiply() from Matrix (see ExERCIse 2.2.12) instead of the equations that compute the new values of \(\mathrm{x} 0\) and
IFS. Experiment with various inputs to IFS to create patterns of your own design like the Sierpinski triangle, the Barnsley fern, or the other examples in the table in the text. You might begin by
Gambler's ruin. Develop a StdRandom client to study the gambler's ruin problem (see Program 1.3.8 and Exercise 1.3.24-25). Note: Defining a static method for the experiment is more difficult than for
Suppose that the standard input stream is a sequence of double values. Write a program that takes an integer \(\mathrm{n}\) and two double values lo and hi from the command line and uses StdStats to
Gaussian random values. Implement the no-argument gaussian() function in StdRandom (Program 2.2.1) using the Box-Muller formula (see ExerCISE 1.2.27). Next, consider an alternative approach, known as
Write a Matrix client that implements the version of Markov described in SeCtion 1.6 but is based on squaring the matrix, instead of iterating the vectormatrix multiplication.
Modify Bernoulli (Program 2.2.6) to animate the bar graph, replotting it after each experiment, so that you can watch it converge to the Gaussian distribution. Then add a command-line argument and an
Write a static method max3() that takes three int arguments and returns the value of the largest one. Add an overloaded function that does the same thing with three double values.
Write a recursive program Ruler to plot the subdivisions of a ruler using StdDraw, as in Program 1.2.1. Program 1.2.1 String concatenation public class Ruler { public static void main(String[] args)
Write a program that takes a command-line argument n and creates an n-by-n boolean matrix with the element in row i and column j set to true if i and j are relatively prime, then shows the matrix on
Modify PercolationProbability to produce output like that produced by Bernoulli (PROGRAM 2.2.6). Extra credit : Use your program to validate the hypothesis that the data obeys a Gaussian
Showing 1 - 100
of 744
1
2
3
4
5
6
7
8