Question
You are given a sequence S of integers (not necessarily positive). The number of integers is n. The problem is to find the consecutive subsequence
You are given a sequence S of integers (not necessarily positive). The number of integers is n. The problem is to find the consecutive subsequence of S with maximum sum. Here, Consecutive means that you are not allowed to skip numbers. For example if the input was 12, 14, 1, 23, 6, 22, 34, 13 the output would be 1, 23, 6, 22.
Now give a linear time dynamic programming algorithm for this problem.
You should explain why a naive recursive solution is not possible. That is, figure out why knowing the i-th number, and the maximum consecutive sum of the first i 1 numbers, is not enough to compute the maximum consecutive sum of the first i numbers. This should give you a big hint how to strengthen the inductive hypothesis
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started