Concept explainers
This exercise deals with the problem of finding the largest sum of consecutive terms of a sequence of n real numbers. When all terms are positive, the sum of all terms provides the answer, but the situation is more complicated when some terms are negative. For example, the maximum sum of consecutive terms of the sequence -2, 3, -1, 6, -7,4 is
a) Use pseudocode to describe an algorithm that solves this problem by finding the sums of consecutive terms starting with the first term, the sums of consecutive terms starting with the second term, and so on, keeping track of the maximum sum found so far as the algorithm proceeds.
b) Determine the computational complexity of the algorithm in part (a) in terms of the number of sums computed and the number of comparisons made.
c) Devise a divide-and-conquer algorithm to solve this problem. [Hint: Assume that there are an even number of terms in the sequence and split the sequence into two halves. Explain how to handle the case when the maximum sum of consecutive terms includes terms in both halves.]
d) Use the algorithm from part (c) to find the maximum sum of consecutive terms of each of the sequences: -2,4,-1,3, 5, -6, 1, 2 4, 1,-3, 7, -1, -5,3, -2; and -1, 6,3, -4, -5,8, -1,7.
e) Find a recurrence relation for the number of sums and comparisons used by the divide-and-conquer algorithm from part (c).
f) Use the master theorem to estimate the computational complexity of the divide-and-conquer algorithm. How does it compare in terms of computational complexity with the algorithm from part (a)?
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
DISCRETE MATHEMATICS LOOSELEAF W/CONNECT
- 2 Q/ Let d₂ +d, di, d2: R² XR² R² defined as follow ((x+x), (2, 1) = √(x-2)² + (x_wx • d₁ ((x,y), (z, w)) = max {1x-z\, \y-w\} • 1 1 dq ((x,y), (Z, W)) = \ x=2\+\-w| 2 • show that dod₁, d₂ are equivalent? 2arrow_forward2 +d, di, d2: R² XR² > R² defined as follow Q/ Let d₂ 2/ d((x+x), (2, 1)) = √(x-2)² + (x-wsc • d₁ ((x,y), (z, w)) = max {| x-z\, \y-w\} • d₂ ((x, y), (Z, W)) = 1x-21+ \y-w| 2 • show that ddi, d₂ are equivalent? އarrow_forwardNumerical anarrow_forward
- 1. Prove the following arguments using the rules of inference. Do not make use of conditional proof. (а) а → (ЪЛс) ¬C ..¬a (b) (pVq) → →r יור (c) (c^h) → j ¬j h (d) s→ d t d -d ..8A-t (e) (pVg) (rv¬s) Лѕ קר .'arrow_forwardThe graph of f(x) is given below. Select each true statement about the continuity of f(x) at x = 1. Select all that apply: ☐ f(x) is not continuous at x = 1 because it is not defined at x = 1. ☐ f(x) is not continuous at x = 1 because lim f(x) does not exist. x+1 ☐ f(x) is not continuous at x = 1 because lim f(x) ‡ f(1). x+→1 ☐ f(x) is continuous at x = 1.arrow_forward2. Consider the following argument: (a) Seabiscuit is a thoroughbred. Seabiscuit is very fast. Every very fast racehorse can win the race. .. Therefore, some thoroughbred racehorse can win the race. Let us define the following predicates, whose domain is racehorses: T(x) x is a thoroughbred F(x) x is very fast R(x) x can win the race : Write the above argument in logical symbols using these predicates. (b) Prove the argument using the rules of inference. Do not make use of conditional proof. (c) Rewrite the proof using full sentences, avoiding logical symbols. It does not need to mention the names of rules of inference, but a fellow CSE 16 student should be able to understand the logical reasoning.arrow_forward
- Find the inverse of the matrix, or determine that the inverse does not exist for: € (b) 7 -12 240 1 1 1 (c) 2 3 2 2 17 036 205 20 (d) -1 1 2 1 T NO 1 0 -1 00 1 0 02 (e) 1 0 00 0 0 1 1arrow_forward4. Prove the following. Use full sentences. Equations in the middle of sentences are fine, but do not use logical symbols. (a) (b) (n+3)2 is odd for every even integer n. It is not the case that whenever n is an integer such that 9 | n² then 9 | n.arrow_forward3. (a) (b) Prove the following logical argument using the rules of inference. Do not make use of conditional proof. Vx(J(x)O(x)) 3x(J(x) A¬S(x)) . ·.³x(O(x) ^ ¬S(x)) Rewrite the proof using full sentences, avoiding logical symbols. It does not need to mention the names of rules of inference, but a fellow CSE 16 student should be able to understand the logical reasoning.arrow_forward
- 3. Pleasearrow_forwardWhat does the margin of error include? When a margin of error is reported for a survey, it includes a. random sampling error and other practical difficulties like undercoverage and non-response b. random sampling error, but not other practical difficulties like undercoverage and nonresponse c. practical difficulties like undercoverage and nonresponse, but not random smapling error d. none of the above is corretarrow_forwarda is done please show barrow_forward
- Algebra: Structure And Method, Book 1AlgebraISBN:9780395977224Author:Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. ColePublisher:McDougal LittellAlgebra & Trigonometry with Analytic GeometryAlgebraISBN:9781133382119Author:SwokowskiPublisher:CengageGlencoe Algebra 1, Student Edition, 9780079039897...AlgebraISBN:9780079039897Author:CarterPublisher:McGraw Hill
- Big Ideas Math A Bridge To Success Algebra 1: Stu...AlgebraISBN:9781680331141Author:HOUGHTON MIFFLIN HARCOURTPublisher:Houghton Mifflin HarcourtCollege Algebra (MindTap Course List)AlgebraISBN:9781305652231Author:R. David Gustafson, Jeff HughesPublisher:Cengage Learning