Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
expand_more
expand_more
format_list_bulleted
Question
Chapter 17.3, Problem 1E
Program Plan Intro
To show that there exist a potential function
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
You are an investor who receives daily price quotes for a stock. The span of a stock's price on a given day
is the number of consecutive days, from the given day going backwards, on which its price was less than
or equal to its price on the day we are considering. Thus, the Stock Span Problem is as follows: Given a
series of daily price quotes for a stock, find the span of the stock on each day of the series.
Assume you are given seven daily stock quotes: 3, 10, 4, 7, 9, 6, and 8.
Assume further that these stock quotes are stored in the array quotes. Show a step-by-step, manual
desk-check execution of the algorithm below showing the values of all variables and arrays for each
step in each cycle of each loop, as demonstrated in clase
Algorithm: A Simple Stock Span Algorithm
SimpleStockSpan (quotes)
spans
Input: quotes, an array with n stock price quotes
Output: spans, an array with n stock price spans
1 spans CreateArray (n)
2 for i-0 to n do
k+1
span_endFALSE
while i-k 20 and not…
You are an investor who receives daily price quotes for a stock. The span of a stock's price on a given day
is the number of consecutive days, from the given day going backwards, on which its price was less than
or equal to its price on the day we are considering. Thus, the Stock Span Problem is as follows: Given a
series of daily price quotes for a stock, find the span of the stock on each day of the series.
Assume you are given seven daily stock quotes: 3, 10, 4, 7, 9, 6, and 8.
Assume further that these stock quotes are stored in the array quotes. Show a step-by-step, manual
desk-check execution of the algorithm below showing the values of all variables and arrays for each
step in each cycle of each loop, as demonstrated in clase
Algorithm: A Simple Stock Span Algorithm
SimpleStockSpan (quotes) → spans
Input: quotes, an array with n stock price quotes
Output: spans, an array with n stock price spans
2
3
4
5
6
7
8
10
11
spans CreateArray (n)
←
for i0 to n do
k 1
span_end FALSE
while…
Fully developed flow moving a 40 cm diameter pipe
has the following velocity profile:
Radius r, cm 0.02.55.07.510.0 12.5 15.0 17.5 20.0
Velocity v, m/s 0.914 0.890 0.847 0.795 0.719
0.543 0.427 0.204 0
Find the volumetric flow rate Q integrate from 0 to R
using the relationship Q = [_0^R_ 2rtrvdr.
Where r is the radial axis of the pipe, R is the radius
of the pipe and v is the velocity. Solve the problem
using two steps.
Fit a polynomial curve to the velocity data using
polyfit.
Integrate the equation using int.
Knowledge Booster
Similar questions
- Consider a maximization problem that is being solved by Simulated Annealing. Let the objective function value of the current state, s, be 1000. Let this state have 5 successors/neighbors: s1(950), s2(975), s3(1000), s4(1000), and s5(1050). The numbers in parentheses represent the corresponding objective function values. The current temperature is 100. The probability that the next state is: 1. s1 = [Select] 2. s2 = [Select] 3. s3 [Select] = 4. s4= [Select] [Select] 5. s5 0.778 0.121 0.156 0.2 0.606arrow_forwardLet X = {1,2,..., 100} , and consider two functions f : X → R and g: X → R. The Chebyshev metric of f and g is given by: d(f,g) = max|f(x) – g(x)| IEX Write a function d (f,g) that calculates the Chebyshev metric of any two functions f and g over the values in X.arrow_forwardIn this question you will explore the Traveling Salesperson Problem (TSP). (a) In every instance (i.e., example) of the TSP, we are given n cities, where each pair of cities is connected by a weighted edge that measures the cost of traveling between those two cities. Our goal is to find the optimal TSP tour, minimizing the total cost of a Hamiltonian cycle in G. Although it is NP-complete to solve the TSP, we found a simple 2-approximation by first generating a minimum-weight spanning tree of G and using this output to determine our TSP tour. Prove that our output is guaranteed to be a 2-approximation, provided the Triangle Inequality holds. In other words, if OP T is the total cost of the optimal solution, and AP P is the total cost of our approximate solution, clearly explain why AP P ≤ 2 × OP T.arrow_forwardA seller has an indivisible asset to sell. Her reservation value for the asset is s, which she knows privately. A potential buyer thinks that the assetís value to him is b, which he privately knows. Assume that s and b are independently and uniformly drawn from [0, 1]. If the seller sells the asset to the buyer for a price of p, the seller's payoff is p-s and the buyer's payoffis b-p. Suppose simultaneously the buyer makes an offer p1 and the seller makes an offer p2. A transaction occurs if p1>=p2, and the transaction price is 1/2 (p1 + p2). Suppose the buyer uses a strategy p1(b) = 1/12 + (2/3)b and the seller uses a strategy p2(s) = 1/4 + (2/3)s. Suppose the buyer's value is 3/4 and the seller's valuation is 1/4. Will there be a transaction? Explain. Is this strategy profile a Bayesian Nash equilibrium? Explain.arrow_forwardA computer company produces hardware and software using the same plant and labor. The total cost of producing computer processing units H and software programs S is given by TC=aH+bS - CHS where a, b, and c are positive. Is this total cost function consistent with the presence of economies or diseconomies of scale? For the product-specific case for hardware, the firm experiences neither economies nor diseconomies of scale. For the product-specific case for software, the firm experiences of scale.arrow_forwardConstruct a graph to show how the time to complete the 10th car changes as the learning curve slope parameter is varied from 75% to 95%. The Mechanical Engineering department has a student team that is designing a formula car for national competition. The time required for the team to assemble the first car is 100 hours. Their improvement (or learning rate) is 0.8, which means that as output is doubled, their time to assemble a car is reduced by 20%. Use this information to determine, Solve, (a) the time it will take the team to assemble the 10th car. (b) the total time required to assemble the first 10 cars. (c) the estimated cumulative average assembly time for the first 10 cars. Solve by hand and by spreadsheet.arrow_forwardDetermine whether each of these functions has a big-Ω relationship.(a) f(x) = 5, ?(x) = x(b) f(x) = 2? − 7, g(x) = x(c) f(x) = ?2 + ? + 2, g(x) = x(d) f(x) = 3? log(?) , g(x) = xarrow_forwardConsider the elliptic curve group based on the equation y? = x* + ax + b mod p where a = 491, b = 1150, and p = 1319. According to Hasse's theorem, what are the minimum and maximum number of elements this group might have? < #E<arrow_forwardProblem 1 (14 points)Show that the autocovariance function can be written asγ(s, t) = E[(xs − μs)(xt − μt)] = E(xsxt) − μsμtwhere E(xt) = μt and E(xs) = μsarrow_forwardConsider the following model of trade between Home and Foreign. Assume throughout that those two countries are the only two countries in the world, at least for purposes of trade. There are two goods: Corn and Radio. Consumers always spend one-third of their income on Corn and the remainder on Radios. The only factor of production is labour. Each home country worker can produce 2 units of Corn or 3 units of Radios per unit of time, while each foreign worker can produce 2 units of Corn or 4 units of Radios per unit of time. There are 30 workers in Home and 60 workers in Foreign. Draw the production possibility frontier for each country (put Corn on the vertical axis and Radios on the horizontal axis).arrow_forwardA particle of (mass= 4 g, charge%3 80 mC) moves in a region of space where the electric field is uniform and is given by E, =-2.5 N/C, E = E, = 0. If the velocity of the particle at t = 0 is given by Vz = 276 m/s, v, = v, = 0, what is the speed of the particle at t = 2 s? %3D (in m/s)arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- Operations Research : Applications and AlgorithmsComputer ScienceISBN:9780534380588Author:Wayne L. WinstonPublisher:Brooks Cole
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole