in reply to Re: Challenge: Sorting Sums Of Sorted Series
in thread Challenge: Sorting Sums Of Sorted Series
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.
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
- Merge Algorithm (Combining Sorted Lists) (iterator version)
- Iterator article I wrote for perl.com
- How A Function Becomes Higher Order
- Higher Order Perl (I recommend you support the author and by the dead tree edition)
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
|
---|
In Section
Seekers of Perl Wisdom