Question: Question 3 {6 points) 8.7.2: Worst-case time complexity - maximum subsequence sum The input is a sequence of numbers a1, air... an. A subsequence is




Question 3 {6 points) 8.7.2: Worst-case time complexity - maximum subsequence sum The input is a sequence of numbers a1, air... an. A subsequence is a sequence of numbers found consecutively within a1, a2 ..... an. For example. in the sequence: -3, -1, 17, 5. 66. 22. -5. 42. both 1?, 5, 66 and -1, 17 are subsequences. However, 66, -5 is not a subsequence because 66 and -5 do not appear consecutively in the sequence. A subsequence can contain only one number such as 66. It can also be empty. In the maximum subsequence sum problem, the input is a sequence of numbers and the output is the maximum number that can be obtained by summing the numbers in a subsequence of the input sequence. If the input was the sequence -3, -1. 17. 5, 66, 22, -5, 42, then the output would be 147 because the sum of subsequence 17, 5, 66, -5, 42 is 14?. Any other subsequence will sum to an equal or smaller number. The empty subsequence sums to 0, so the maximum subsequence sum will always be at least 0. The algorithm below computes the maximum subsequence sum of an input sequence. MaximumSubsequenceSum Input: a1, a2, . . . an n, the length of the sequence. Output: The value of the maximum subsequence sum. maxSum := 0 For i = 1 to n thissum : = 0 For j = i to n thissum := thissum + a; If ( thissum > maxsum ) , maxsum := thissum End-for End-for Return ( maxsum ) (a) Characterize the asymptotic growth of the worst-case time complexity of the algorithm (both lower and upper bound). Justify your
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
