title: Generic sub-set algorithm problem
body: <p>I have the following problem.</p>
  
  <p>I've got a set of items <code>{a1, a2, a3, ... aN}</code>. Each one of those items can contain another set of items <code>{b1, b2, b3, ... bN}</code>. So the end result looks something like this:</p>
  
  <pre><code>a1
    b4
    b22
    b40
    b11
    b9
  a2
    b30
    b23
    b9
    b4
    b11
  a3
    b22
    b4
    b60
    b9
  </code></pre>
  
  <p>As a result of the execution of the algorithm I would like to get the groups of b-type objects that fall under following rules:</p>
  
  <ol>
  <li>If more than one b-type object under an a-type object only exists under that a-type object, they should be grouped.</li>
  <li>If more than one b-type object is used in more then one a-type object they also should be grouped.</li>
  </ol>
  
  <p><strong>Example:</strong></p>
  
  <pre><code>b4, b9
  b30, b23
  
  b40, b60, b11 and b22 shouldn't be grouped because there are no pairs for them.
  </code></pre>
  
  <p>I would be writing the implementation of this algorithm in C#, so it would be nice to avoid data structures that don't exist in it, such as binary trees, linked lists, etc. But this is not a requirement; all of these could be implemented too.</p>
  
  <p><strong>Clarification</strong>: Sets can contain as many objects as needed, but not more than 1 of each. The rules are that all unique objects of b-type within the same a-type should be grouped (more than 1), and if more than 1 b-type object fall within more than 1 a-type object, they should be grouped. The groups should be as large as possible.</p>
  
  <p><strong>Real life example</strong>: Web-pages are <em>a-type</em> and the CSS files used on those pages are <em>b-type</em>. In order to speed up the loading of the pages, you want to have as few requests as possible going to the server, so you combine CSS files, but you don't want to combine files that are used by themselves only on a few pages, since they will be cached and you don't have to re-download them again.</p>