i'm pretty sure this has been asked a million times before, but i couldn't come up with search keywords (which you probably can tell by the awkward topic title)

following problem:

i have got a set M of arbitrary data values of the same type.

now i have some random algorithm which pairs them up and puts them into a list, obeying the rule that although a data value may appear in several pairs, the symmetric counterpart (e.g. for the pair values <A,B>, with A,B in M, this would be the pair <B,A>) should not. also, no pair should appear twice.

the elements have, needless to say, no intrinsic ordering relation (else you could sort the pair to have the smaller always first, and would only need to check for the this item when looking if it already exists).

the obvious approach would be to search the entire list first item for A, and check if the pairing with B exists, then search the list's first item for B, and check if the pairing with A exists. if not, add the pair.

i am aware that in programming, you can always define an ordering relation by interpreting the data as a stream of 0 and 1, and use the induced ordering, but it seems so weak a solution. this problem just 'feels' like it can be solved more elegantly. if an ordering were used, what would be the quickest way? the one i mentioned using a sorted list?

i also hope i haven't offended anyone (or perhaps even clouded the question and/or assumptions) by my horrible translation of german math lingo into english.

cheers,

tasche

**Edited by Tasche, 04 February 2013 - 02:10 PM.**