Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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 ?


  • 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
    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.

    Here are a few links to help your main question

    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
    Just some ideas on how you can answer your questions:

    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:

    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...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://821097]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2018-07-20 13:02 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (431 votes). Check out past polls.