Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Fast Way to find one array in second array (updated)

by LanX (Saint)
on Aug 14, 2016 at 21:20 UTC ( [id://1169766]=note: print w/replies, xml ) Need Help??


in reply to Fast Way to find one array in second array

Let X < Y denote set X included in set Y.

Instead of speeding up the process to check X < Y , let's reduce the potential number of such checks.

At the moment you are ordering all sets S and testing for each X if you find a bigger Y with X < Y, and then you go on with the next X'.

This means a worst case of n(n-1)/2 tests for n sets (no inclusions found)

And at some point you start checking all sets bigger Y to find a Z with Y < Z.

BUT

X < Y < Z   =>   X < Z

So instead of stopping after finding Y record all X* := { S | X < S } and push X into Y° := { S | S < Y }.

Once you reach Y you'll only have to check Y against the sets S in the intersection of all X* for X in Y°.

The worst case of this approach is the same, but I'm sure it'll be faster on average.²

Such algorithms can certainly be found in literature, but I don't have the time to check now. ³

HTH

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

²) I suppose this approach is more efficient if you stop growing a X* after it reached a certain size - like n/2 or so - and take X out of consideration.

³) probably looking for keyword "posets" = partially ordered sets

update

On second thought, restricting to calculate X* only for those X ( atoms ) which don't have a lower neighbor, i.e. there is no X' < X  <=>   X° is empty so far , should be good enough.

Then - visually speaking - those X with an X* form "axes" of the poset and the Y° are the "coordinates" of Y - like when embedded in a n* dimensional cube.

I'll implement this after YAPC, feel free to do earlier...

update

In hindsight for this particular task it might be more efficient to apply this to the dual poset. That is starting with the biggest sets and on the fly calculating the coatoms Y, which have no superset. For any S with S < X there must be a coatom with S < X <= Y.

  • Comment on Re: Fast Way to find one array in second array (updated)

Replies are listed 'Best First'.
Re^2: Fast Way to find one array in second array
by hippo (Bishop) on Aug 15, 2016 at 08:25 UTC
    Let X < Y denote set X included in set Y.

    This is called a subset and there is already a character used for it so you don't actually need to overload the < character. Even better, it is a named entity in HTML so even unicode-unfriendly sites can use it. The entity is called "sub" and here it is in use:

    X ⊂ Y

    If you use this to mean "X is a subset of Y" then the meaning should be clear to anyone familiar with set theory. HTH.

      If you use this to mean "X is a subset of Y" then the meaning should be clear to anyone familiar with set theory.

      All of which will make his diatribe more 'correct' in certain circles but just as meaningless.

      Set theory is as much help to anyone implementing an efficient practical algorithm as Bernoulli principle is to someone constructing a model plane.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
      In mathematics it's common to redefine symbols if needed.

      Like when you can't easily access unicode characters ... :)

      There are also already other symbols in use for X° and X*

      edit

      Anyway < is the common symbol for the binary relation of posets ...

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1169766]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 01:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found