-3

So the following input in an array would be something like

  Array: {7 2 5 -3 3 6 -4 1}

and the subsequence would be

 Subseq: : 7 2 5 -3 3 6

and the answer to the largest sum would be 20. So, what exactly is going on here. I am not understanding the concept of a subsequence. After reading, I thought the subsequence started at array[0] and went through to array[n] and picked the largest numbers but that does not seem to be the case because the numbers should have stopped after the number 7 then. I am confused on what exactly a subsequence is doing with this user entered array.

CodeFreak
  • 90
  • 1
  • 2
  • 15
  • We are not a "explain my homework" site. Ask your tutor. It is his job to teach you and explain if you have questions. – too honest for this site Apr 19 '17 at 00:14
  • @olaf if you could explain a concept, I could do my homework. I don't understand what is going on here because to me, the answer should be 7 because as soon as it reaches a lower number, shouldn't the code stop. I wasn't asking you to do it but thank you for your comment – CodeFreak Apr 19 '17 at 00:24

3 Answers3

1

What he is really finding is a sum of a lot of values together so he can get the maximum number possible. Stop at 7 it just give the total o 7.

7 2 = 9

7 2 5 = 14

7 2 5 - 3 = 11

7 2 5 - 3 3 = 14

7 2 5 -3 3 6 = 20
0

After the above help, the reason for my confusion was being unsure of exactly what a subsequence is doing. However, I now understand that it is taking the largest grouping of numbers and adding them together. In my example of numbers:

 Array: {7,2,5,-3,3,6,-4,1}

It takes the digits:

 Answer: {7,2,5,-3,3,6}              //adds to = 20

This is the largest sum of a continuous sequence of numbers.

Another example of a simple subsequence would be:

 Array: {-5 -10 5 5 -5 -10}
 Answer:{5, 5}   //it adds 5 and 5 because that is the largest continuous sequence (10)
CodeFreak
  • 90
  • 1
  • 2
  • 15
-1

Your title answers your question: largest sum of subsequence

So you have to find elements in the array whose sum is maximum. In this case : 7+2+5-3+3+6 = 20

user968000
  • 1,765
  • 3
  • 22
  • 31
  • that kind of makes sense but how would someone go about that. Is there a specific algorithm to follow? I don't get how it would keep checking because once it reaches a negative number, I assume that the it should stop. Not sure if that comment is clear but I understand what you said – CodeFreak Apr 19 '17 at 00:26