Creating combinations that have no more one intersecting element

Posted by khuss on Stack Overflow See other posts from Stack Overflow or by khuss
Published on 2010-06-02T05:56:05Z Indexed on 2010/06/02 6:53 UTC
Read the original article Hit count: 300

I am looking to create a special type of combination in which no two sets have more than one intersecting element. Let me explain with an example:

Let us say we have 9 letter set that contains A, B, C, D, E, F, G, H, and I

If you create the standard non-repeating combinations of three letters you will have 9C3 sets. These will contain sets like ABC, ABD, BCD, etc. I am looking to create sets that have at the most only 1 common letter. So in this example, we will get following sets:

ABC, ADG, AEI, AFH, BEH, BFG, BDI, CFI, CDH, CEG, DEF, and GHI - note that if you take any two sets there are no more than 1 repeating letter.

What would be a good way to generate such sets? It should be scalable solution so that I can do it for a set of 1000 letters, with sub set size of 4.

Any help is highly appreciated.

Thanks

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about algorithm-design