Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Algorithm

Name: Anonymous 2010-10-21 11:53

There's a n-element array of integers- 1 or 2.
We have to find subsequence which sum equals x.
How to do that ? I have no fucking idea.
Inb4 bruteforce

Name: Anonymous 2010-10-21 23:56

>>24
>Let the input be {2 1 2} and let x = 4.  This algorithm will not find a solution.

If we're talking about subsequences in the mathematical sense (c.f. http://en.wikipedia.org/wiki/Subsequence) then the solution here is {2 2}. If we're talking about substrings (i.e. contiguous subsequences) then there's no solution.

>>21
The correct version >>18 is O(n).

It can't be O(n). A string of length N has sum [1..N] == (N*(N+1))/2 substrings. Since you have to check O(N^2) substrings to find the solution, a correct algorithm will be at least O(N^2).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List