### Re: Challenge: Sorting Sums Of Sorted Series

by Krambambuli (Curate)
 on Feb 03, 2010 at 08:12 UTC ( #821097=note: print w/replies, xml ) Need Help??

in reply to Challenge: Sorting Sums Of Sorted Series

Can't help, have to ask this question:

how would an algorithm that would deal with this problem for infinite (huge...) lists look like...?

Update: And, given a finite part of each serie, a1, ..., aN, b1, ..., bM, how many - which - terms of the result could be trustfully computed (knowing that there are other terms to follow) ?

And how far could we advance with the 'arrival' of aN+1 and/or bM+1...?

hmmmm... Is someone aware of some good readings in order to get the answers ?

Thanks,

Krambambuli
---
• Comment on Re: Challenge: Sorting Sums Of Sorted Series

Replies are listed 'Best First'.
Re^2: Challenge: Sorting Sums Of Sorted Series
by Limbic~Region (Chancellor) on Feb 03, 2010 at 14:05 UTC
Krambambuli,
Before answering your question, keep in mind I already allowed for both lists to fit in memory as a given. In reality, if you had a really large list you probably wouldn't be going through these contortions - you would probably sort on disk.

I guess your question boils down to: How can you do this with even less than 2N + M? blokhead has shown a solution that uses no memory but takes (N*M)^2 to run. TO give you a specific answer, one would need a specific problem. As I demonstrated in How many words does it take?, the trick to solving really hard problems in the general case (NP complete) is to exploit the details of the specific case (effectively turned into O(1)).

Cheers - L~R

Re^2: Challenge: Sorting Sums Of Sorted Series
by rubasov (Friar) on Feb 03, 2010 at 13:11 UTC

For representing infinite lists I recommend you to read Mark Jason Dominus' excellent book named Higher Order Perl, especially the chapter on infinite lists (where he is using closures for iterators and promise-forcing streams). It is available online in pdf format: http://hop.perl.plover.com.

And for your updated question: given the finite parts (a1, ..., aN), (b1, ..., bM), if you take min(a1+bM, b1+aN), you are safe to print any sum less than or equal to this threshold as a beginning sequence of the final list. Anything above this threshold cannot be considered final.

update: First I've written this: min(a1, b1) + min(aN, bM), but this is wrong, corrected above. And minor grammatical edits, arrgh...

Create A New User
Node Status?
node history
Node Type: note [id://821097]
help
Chatterbox?
 [ambrus]: The 0.2 seconds wakeup is likely a workaround for some bug, but I can't guess what bug that is. [ambrus]: It's been there since Prima 1.00 iirc [Corion]: Hmmm... Weird. Maybe it needs that for doing its timers or something. Still weird. [Corion]: But I guess I'll find out soonish, as my application seems to use Prima for more than just displaying the OpenGL output soonish ;)) [ambrus]: No, I think the timers are handled fine in the event loop, as far as I can see. [Corion]: So far, I liked Prima quite well as it simply seems to do what I want even if it has an upside-down coordinate system. But it installs from CPAN out of the box and is cross-platform

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2016-12-09 10:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
On a regular basis, I'm most likely to spy upon:

Results (150 votes). Check out past polls.