Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > sci.math > #325283

Re: Algorithm involving binary strings.

Path csiph.com!feeder.erje.net!2.us.feeder.erje.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!panix.com!forkosh
From JohnF <john@please.see.sig.for.email.com>
Newsgroups sci.math
Subject Re: Algorithm involving binary strings.
Date Thu, 31 Dec 2015 06:53:23 +0000 (UTC)
Organization PANIX Public Access Internet and UNIX, NYC
Lines 48
Message-ID <n62jd3$kmf$1@reader1.panix.com> (permalink)
References <4f1a0e21-4563-4697-8b6e-b4c41f8381ae@googlegroups.com>
NNTP-Posting-Host panix3.panix.com
X-Trace reader1.panix.com 1451544803 21199 166.84.1.3 (31 Dec 2015 06:53:23 GMT)
X-Complaints-To abuse@panix.com
NNTP-Posting-Date Thu, 31 Dec 2015 06:53:23 +0000 (UTC)
User-Agent tin/1.6.2-20030910 ("Pabbay") (UNIX) (NetBSD/6.1.5 (i386))
Xref csiph.com sci.math:325283

Show key headers only | View raw


Paul <pepstein5@gmail.com> wrote:
> Suppose we are given a collection of binary strings all of
> the same length. The problem is to find the largest number n
> such that there exist distinct strings s1, s2 such that n positions
> are set to 1 in both s1 and s2 simultaneously. Also, the task
> is to find all pairs so that this maximum is realised.
> 
> This is easy to do but difficult to do efficiently.  Could someone
> help me, perhaps by referencing the right techniques to look at? 
> 
> No, this isn't a homework problem. No, I'm not enrolled in any
> courses. I'm trying to learn some computer science.
> Thanks, Paul

(a) just curious: what suggested this problem to you?
To me, as far as I can tell, it seems pretty useless,
application-wise. And if you're "trying to learn some
computer science", one of the first things to learn is
recognizing useful or theoretically important problems.
And, unless I'm wrong, this ain't one. But please correct
me if I'm wrong about that -- then I'll learn something:).

(b) there's efficient wrt computational complexity, and
efficient wrt making efficient use of hardware architecture.
I can't say about the first, but you can make use of 8-bit
byte addressability of virtually all architectures, as follows.
First, if n isn't a multiple of 8, concat some 0 bits to each
string so that it is. Now munge through each string byte-by-byte.
And have a 256-int table with nOnes[i]=the number of 1's for
value i, e.g., nOnes[0]=0, [3]=2, [16]=1, [255]=8.
Then just sum up nOnes for each byte of a string. That'll reduce
your loop by a factor of 8. (And I leave you to answer why munging
through your string 32-bit-int by 32-bit-int isn't optimal.)
And once you know the number of 1's in each string, the
rest is easy ... except for uniqueness. If your collection
of strings may contain duplicates, you'll also want to
accumulate some md5-like hash of each string as you munge
through them.

(c) you just talking about learning, or you going to
show us some code? Here's the function prototype in C,
   int nones ( unsigned char *s, int len )
   /* s = ptr to bit string (beginning on byte boundary) */
   /* len = total #bits in s */
   /* returns #bits in s that are 1's */
Please follow up with that function...
-- 
John Forkosh  ( mailto:  j@f.com  where j=john and f=forkosh )

Back to sci.math | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Algorithm involving binary strings. Paul <pepstein5@gmail.com> - 2015-12-30 09:41 -0800
  Re: Algorithm involving binary strings. Virgil <VIRGIL@VIRGIL.com> - 2015-12-30 13:16 -0700
  Re: Algorithm involving binary strings. quasi <quasi@null.set> - 2015-12-30 16:30 -0500
    Re: Algorithm involving binary strings. James Waldby <not@valid.invalid> - 2015-12-31 01:18 +0000
  Re: Algorithm involving binary strings. JohnF <john@please.see.sig.for.email.com> - 2015-12-31 06:53 +0000
    Re: Algorithm involving binary strings. Paul <pepstein5@gmail.com> - 2015-12-31 06:46 -0800
      Re: Algorithm involving binary strings. Paul <pepstein5@gmail.com> - 2015-12-31 07:38 -0800
        Re: Algorithm involving binary strings. John Forkosh <forkosh@panix.com> - 2016-01-01 02:19 +0000
          Re: Algorithm involving binary strings. JohnF <john@please.see.sig.for.email.com> - 2016-01-01 11:44 +0000
          Re: Algorithm involving binary strings. Paul <pepstein5@gmail.com> - 2016-01-01 05:00 -0800
            Re: Algorithm involving binary strings. JohnF <john@please.see.sig.for.email.com> - 2016-01-02 02:11 +0000
              Re: Algorithm involving binary strings. Paul <pepstein5@gmail.com> - 2016-01-02 02:20 -0800
                Re: Algorithm involving binary strings. JohnF <john@please.see.sig.for.email.com> - 2016-01-02 12:50 +0000
                Re: Algorithm involving binary strings. Paul <pepstein5@gmail.com> - 2016-01-02 07:12 -0800
                Re: Algorithm involving binary strings. JohnF <john@please.see.sig.for.email.com> - 2016-01-03 04:55 +0000

csiph-web