Re: Looking for a fast algorithm



frederik_coppens@xxxxxxxxx wrote:
Now, it's possible to make sequences of objects by taking an object
from every row, and to associate a number with each such sequence by
multiplying the numbers of every object. It's clear that the sequence
with the highest number will be the one obtained by taking the first
object of every row. But how do I find the X highest sequences?

I have no idea if this is optimal, but here's how I'd do it:

For one row the problem is trivial. For n+1 rows, recursively calculate the stream (lazy list) of highest-to-lowest sequences for all rows but the first; then multiply that stream by the k different object values from the first row, obtaining k streams; then compute the merge of those streams. A quick mental calculation suggests that taking the first X elements of the result will cost O(X log (k1 k2 ... kn)) steps, which looks reasonable, since with X = k1 k2 ... kn it matches the cost of the obvious approach of pregenerating all the sequences and sorting them.

-- Ben
.



Relevant Pages

  • Re: Unicode Problem: SBCL(running on FreeBSD)
    ... decoding error on stream ... Not all Shift-JIS sequences are valid UTF-8 sequences (and even if ... The HTTP protocol, despite initial appearances, is a binary protocol. ...
    (comp.lang.lisp)
  • Re: Unicode Problem: SBCL(running on FreeBSD)
    ... www.google.co.jp doesn't send utf-8, but sends Shift-JIS, at least ... decoding error on stream ... Not all Shift-JIS sequences are valid UTF-8 sequences (and even if ... The HTTP protocol, despite initial appearances, is a binary protocol. ...
    (comp.lang.lisp)
  • Re: zlib and NULLs
    ... since random data will usually generate a ... a decompression error is a sequence that can't occur in compressed data. ... It is not a contradiction for floating sequences. ... cannot occur anywhere in the stream. ...
    (comp.compression)
  • Re: Could UNIX I/O be Made Type-Safe?
    ... He's defining grep to specifically accept and produce ... whatever stream format from it, adding type information back in as ... Where "arbtext2xml" fails if its input is not valid. ... generalisation would be to let them be "sequences of things". ...
    (comp.unix.programmer)
  • Fast PRNG
    ... For hard disk torture testing purpose, ... sequences of randomish bytes with the following constraints: ... Accept different seeds (need to use different sequences on ... stream would be a plus. ...
    (comp.graphics.algorithms)