Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Extendable pairwise indexes - prior work?

by pjf (Curate)
on Apr 02, 2007 at 07:27 UTC ( [id://607769]=note: print w/replies, xml ) Need Help??


in reply to Re: Extendable pairwise indexes - prior work?
in thread Extendable pairwise indexes - prior work?

My apologies, I probably should have included an example. The important thing to note is that since we're storing information on unordered pairs, so that (0,1) is the same as (1,0). Hence the requirement that X > Y to find the index allows us to cover all possible pairs:

for my $x (0..5) { for my $y (0..$x-1) { print "Info for pair ($x, $y) is stored at: ",$x*($x-1 +)/2+$y,"\n"; } }

Which provides the output:

Info for pair (1, 0) is stored at: 0
Info for pair (2, 0) is stored at: 1
Info for pair (2, 1) is stored at: 2
Info for pair (3, 0) is stored at: 3
Info for pair (3, 1) is stored at: 4
Info for pair (3, 2) is stored at: 5
Info for pair (4, 0) is stored at: 6
Info for pair (4, 1) is stored at: 7
Info for pair (4, 2) is stored at: 8
Info for pair (4, 3) is stored at: 9
Info for pair (5, 0) is stored at: 10
Info for pair (5, 1) is stored at: 11
Info for pair (5, 2) is stored at: 12
Info for pair (5, 3) is stored at: 13
Info for pair (5, 4) is stored at: 14

The important thing to note here is that as the range expands we're able to encode the additional pairs created by the addition of extra elements into our potential array.

As a simple example, I'm using this to store information about undirected graphs, where every vertex may contain a link to any other vertex, and the graph can grow over time. By using the algorithm described above we can encode the entire graph as a bitstring, with each position indicating the presence (true) or absence (false) of an edge between two nodes.

The whole thing works just fine, but I'm certain it's not an original algorithm, hence my seeking of wisdom before anything goes up on the CPAN.

Replies are listed 'Best First'.
Re^3: Extendable pairwise indexes - prior work?
by BrowserUk (Patriarch) on Apr 02, 2007 at 07:36 UTC

    Yes. That makes much more sense now. I did see the X < Y criteria in the OP (which incidentally you've reversed in the above post?), and thought that was what I was missing, but I didn't immmediately see how it was applied.

    I don't have any reference to prior art to offer, though I will have a look around to see what I can turn up--but presumably you've already done this. It can be quite hard to know what to search for in the situations.

    I like the idea of a graphing module based around this and bitstrings, it sounds like it could be quite efficient in terms of both time and memory, unlike the existing implementations I've tried.

    Good luck with it.

    Update: Maybe this is related to the problem?


    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".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2024-04-23 12:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found