Daniel Etzold wrote:
> A consecutive series in the array? Is this really what you
> are looking for?
>
> input: N, a[0..n-1]
>
> l=r=c=0
> while r < n && c < N do
>    while c < N && r < n do
>      c = c + a[r]
>      r = r + 1
>    od
>    while c > N do
>      c = c - a[l]
>      l = l + 1
>    od
> od
> if c == N then return "yes"
> return "no"
>

This doesn't work in many cases.  Consider

n = 1, N = -1, a[0] = -1 .  (Algorithm says no, subseq exists.)

Or a more interesting example,

n = 4, N = 2, a = [1, -2, 5, -2]  (Again alg says no, subseq exists.)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to