- Write a short Python function that takes a string s, representing a sentence, and returns a copy of the string with all punctuation removed. For
- Write a short program that takes as input three integers, a, b, and c, from the console and determines if they can be used in a correct arithmetic
- Write a Python program that can take a positive integer greater than 2 as input and write out the number of times one must repeatedly divide this
- Write a Python program that can “make change.” Your program should take two numbers as input, one that is a monetary amount charged and the other
- Write a Python program that can simulate a simple calculator, using the console as the exclusive input and output device. That is, each input to the
- Write a Python program that simulates a handheld calculator. Your program should process input from the Python console representing buttons that are
- A common punishment for school children is to write out a sentence multiple times. Write a Python stand-alone program that will write out the
- The birthday paradox says that the probability that two people in a room will have the same birthday is more than half, provided n, the number of
- Write a Python program that inputs a list of words, separated by whitespace, and outputs how many times each word appears in the list. You need not
- Give an example of a software application in which adaptability can mean the difference between a prolonged lifetime of sales and bankruptcy.
- Write a Python class, Flower, that has three instance variables of type strint, and float, that respectively represent the name of the flower, its
- If the parameter to the make payment method of the CreditCard class were a negative number, that would have the effect of raising the balance on the
- Suppose you are on the design team for a new e-book reader. What are the primary classes and methods that the Python software for your reader will
- Write a Python class that extends the Progression class so that each value in the progression is the square root of the previous value. (Note that
- Write a Python program that inputs a polynomial in standard algebraic notation and outputs the first derivative of that polynomial.
- Write a Python program that inputs a document and then outputs a barchart plot of the frequencies of each alphabet character that appears in that
- Write a set of Python classes that can simulate an Internet application in which one party, Alice, is periodically creating a set of packets that she
- Write a Python program to simulate an ecosystem containing two types of creatures, bears and fish. The ecosystem consists of a river, which is
- Write a simulator, as in the previous project, but add a Boolean gender field and a floating-point strength field to each animal, using an Animal
- Write a Python program that simulates a system that supports the functions of an e-book reader. You should include methods for users of your system
- Develop an inheritance hierarchy based upon a Polygon class that has abstract methods area( ) and perimeter( ). Implement classes Triangle,
- Perform an experimental analysis of the three algorithms prefix_average1, prefix_average2, and prefix_average3, from Section 3.3.3. Visualize their
- Describe a recursive function for computing the nth Harmonic number, Hn = Σni=1 1/i.
- Describe how the built-in sum function can be combined with Python’s comprehension syntax to compute the sum of all numbers in an n×n data set,
- The shuffle method, supported by the random module, takes a Python list and rearranges it so that every possible ordering is equally likely.
- Perform experiments to evaluate the efficiency of the remove method of Python’s list class, as we did for insert on page 205. Use known values so
- Suppose an initially empty queue Q has executed a total of 32 enqueue operations, 10 first operations, and 15 dequeue operations, 5 of which raised
- What values are returned during the following sequence of deque ADT operations, on initially empty deque? add first(4), add last(8), add last(9), add
- Our implementation of shortest path lengths in Code Fragment 14.13 relies on use of “infinity” as a numeric value, to represent the distance
- An old MST method, called Bar ˚uvka’s algorithm, works as follows on a graph G having n vertices and m edges with distinct weights:Let T be a
- Describe the meaning of the graphical conventions used in Figure 14.9 illustrating a DFS traversal. What do the line thicknesses signify? What do the
- There are eight small islands in a lake, and the state wants to build seven bridges to connect them so that each island can be reached from any other
- Can edge list E be omitted from the adjacency list representation while still achieving the time bounds given in Table 14.3? Why or why not?
- In order to verify that all of its nontree edges are back edges, redraw the graph from Figure 14.8b so that the DFS tree edges are drawn with solid
- In the previous exercise, we assume that the underlying list is initially empty. Redo that exercise, this time preallocating an underlying list with
- To implement the iter method of the PositionalList class, we relied on the convenience of Python’s generator syntax and the yield statement. Give
- Answer the following questions so as to justify Proposition 8.8.a. What is the minimum number of external nodes for a proper binary tree with height
- Modify our in-place quick-sort implementation of Code Fragment 12.6 to be a randomized version of the algorithm, as discussed in Section 12.3.1.
- Draw an adjacency matrix representation of the undirected graph shown in Figure 14.1.
- Draw an adjacency list representation of the undirected graph shown in Figure 14.1.
- Repeat Exercise R-14.7 for the adjacency list representation, as described in the chapter.Exercise R-14.7Give pseudo-code for performing the
- Can edge list E be omitted from the adjacency matrix representation while still achieving the time bounds given in Table 14.1? Why or why not?
- In some applications, such as in computer vision, an input set of two-dimensional points can be assumed to be given as pairs of integers, rather than
- Consider the substring pattern matching problem for a length-m pattern, P, and a length-n text, T, where one of the characters in P is a symbol,
- Describe how to compute shiftHash(h(X[i..i+m−1]), X, i) for the hash function, h(X[i..i + m − 1]) = X[i] + ··· + X[i + m − 1], where each
- Show the existence of additive inverses in Zp, that is, prove that for each x ∈ Zp, there is a y ∈ Zp, such that x + y mod p = 0.
- What is 960 mod 77?
- Show that 5 is a multiplicative generator of the positive numbers in Z17.
- Give a linear programming formulation to find the minimum spanning tree of a graph. Recall that a spanning tree T of a graph G is a connected acyclic
- What is the dual of the following linear program?
- Give a linear programming formulation for the all-pairs shortest-path problem.
- Formulate the dual of the linear program for the maximum flow problem.
- Give an objective function for the feasible region shown in Figure 26.9, such that there are an infinite number of optimal solutions, none of which
- The maximum independent set (MIS) of a graph G = (V,E) is the largest set of vertices S ⊆ V such that for any two vertices u, v ∈ S, (u, v) ∈/
- For each vertex, (3, 9) and (8, 6), of the feasible region shown in Figure 26.9, give an objective function that has that vertex as the optimal
- Prove that if there exists a point that is feasible in both a linear program and its dual, then that point is the optimal solution in both linear
- Give a set of linear programming constraints that result in the feasible region shown in Figure 26.9. Figure 26.9.
- Show that if we allow linear programs to have strict inequalities, then there exists a linear program which is neither infeasible nor unbounded, but
- Suppose you are part of a trade expedition and there are 15 people in your party (including yourself). Your final destination lies across the desert,
- If P is a linear program, let P∗ denote the dual of P, and let Pk∗ denote k application of the dual function. For example P2∗ = (P∗)∗ is
- Suppose there are four power plants, which use coal, nuclear, wind, and oil, and four cities, Flat Top Mountain, Zephyrville, Cherenkov, and
- Given a linear program in slack form such that the basic solution is feasible, give an algorithm to find a vertex of the feasible region by
- For each of the regions shown in Figure 26.8, give an LP for which that region is the feasible region, or explain why no such linear program
- A small retail chain has three warehouses and four retail stores. Each warehouse stores a certain amount of goods, and each retail store has a demand
- When the simplex method was introduced, we assumed that the basic solution of the slack form was a feasible solution. Describe an algorithm that
- Solve the linear program of Exercise R-26.4, for α = 1, using the simplex method. Show the result of each pivot. Data FroExercise R-26.4,In the
- A perfect pizza maximizes how great it tastes and meets your recommended daily allowance (RDA) for the three macronutrients carbohydrates, fats, and
- Give a linear program in three variables for which the feasible region is a tetrahedron.
- In the following linear program, the objective function has a parameter, α. What values of α result in a program with no unique solution?
- A political candidate has hired you to advise them on how to best spend their advertising budget. The candidate wants a combination of print, radio,
- Prove that the set of feasible solutions to a linear program with a nonempty feasible region is convex.
- Suppose that instead of maximizing hits per minute, constraints, a web server company wants to minimize cost while maintaining a rack of standard and
- Suppose that you are preparing for the upcoming Zombie Apocalypse. The Centers for Disease Control and Prevention recommend that any Zombie
- Prove that if there exists more than one optimal solution to a linear program, then there must be infinitely many optimal solutions.
- Prove that there exists a linear program in two variables with exactly one feasible solution.
- Recall at the beginning of the chapter we gave a linear program to help a web server company decide what server models it should purchase. Suppose
- What is the exact number of recursive calls made to compute the convolution of the vectors [6, 2, 3, 5, 2, 5, 8, 3, 2, 6] and [4, 2, 3, 2, 7, 3, 3,
- In financial and scientific data analysis applications, such as in spotting trends in stocks, we are often interested in making sense of noisy or
- Compute the product of the binary numbers (01101000)2 and (10001011)2 using the algorithm given in the book.
- Compute the discrete Fourier transform of the vector [5, 4, 3, 2] using arithmetic modulo 17 = 24 + 1. Use the fact that 5 is a generator for the
- Consider a further generalization of the pattern matching problem from the previous exercise, where we allow the pattern, P, to contain instances of
- Use the convolution theorem to compute the product of the polynomials p(x) = 3x2 + 4x + 2 and q(x)=2x3 + 3x2 + 5x + 3, using arithmetic in Z17. You
- Consider a generalization of the pattern matching problem from the previous exercise, where we allow the pattern P and text T to be strings defined
- Describe a method for computing the coefficients of the polynomial, P(x)=(x + 1)n, in O(n) time.
- Use the FFT and inverse FFT to compute the convolution of a = [1, 2, 3, 4] and b = [4, 3, 2, 1], using arithmetic in Z17. Use the fact that 5 is a
- Suppose you have a software method, Conv, that can perform the convolution of two length-n integer vectors, A and B, using the FFT algorithm
- Describe a version of the FFT that works when n is a power of 3 by dividing the input vector into three subvectors, recursing on each one, and then
- In some numerical computing applications, a desired computation is to find a polynomial that goes through a given set of points on a line, which,
- Given degree-n polynomials p(x) and q(x), describe a method for multiplying the derivatives of p(x) and q(x), that is, p'(x)·q'(x), using O(n log n)
- What is the bit-reversal permutation, reverse, for n = 16?
- Prove that ω = 24b/m is a primitive mth root of unity when multiplication is taken modulo (22b + 1), for any integer b > 0 that is a multiple of
- Write the complex nth roots of unity for n = 4 and n = 8 in the form a + bi.
- Prove the following more general form of the reduction property of primitive roots of unity: For any integer c > 0, if ω is a primitive (cn)th
- Describe the inverse FFT algorithm, which computes the inverse DFT in O(n log n) time. That is, show how to reverse the roles of a and y and change
- Construct a table showing an example of the RSA cryptosystem with parameters p = 17, q = 19, and e = 5. The table should have two rows, one for the
- Why can’t you use the pair (1, n) as an RSA public key, even if n = pq, for two large primes, p and q?
- Suppose the primes p and q used in the RSA cryptosystem, to define n = pq, are in the range [√n − log n, √n + log n]. Explain how you can
- Solve the previous exercise, but use the El Gamal cryptosystem instead of RSA.Data From Previous ExerciseSuppose Alice wants to send Bob a message,
- Suppose Alice wants to send Bob a message, M, that is the price she is willing to pay for his old bike. Here, M is just an integer in binary. She
- Write a nonrecursive version of Algorithm ExtendedEuclidGCD.