title: Efficient algorithm to produce the n-way intersection of sorted arrays in C
body: <p>I need to produce the intersection between some sorted arrays of integers in C. I know how to find the intersection between two sorted arrays, but I need to do this for more than two arrays, efficiently and without prior knowledge of the number of arrays. I can impose a sensible limit on the maximum number - let's say ten for now. These arrays could be anywhere from a few items to a couple of hundred thousand items long, and are by no means necessarily the same length.</p>
  
  <p>Pseudo-code for producing the intersection of two sorted arrays:</p>
  
  <pre><code>while i &lt; m and j &lt; n do:
      if array1[i] &lt; array2[j]:
          increment i
      else if array1[i] &gt; array2[j]: 
          increment j
      else 
          add array1[i] to intersection(array1, array2)
          increment i
          increment j
  </code></pre>
  
  <p>I am working with C, and I am after a clear explanation rather than code.</p>