title: Minimum no. of comparisons to find median of 3 numbers
body: <p>I was implementing quicksort and I wished to set the pivot to be the median or three numbers. The three numbers being the first element, the middle element, and the last element.</p>
  
  <p>Could I possibly find the median in less no. of comparisons? </p>
  
  <pre><code>median(int a[], int p, int r)
  {
      int m = (p+r)/2;
      if(a[p] &lt; a[m])
      {
          if(a[p] &gt;= a[r])
              return a[p];
          else if(a[m] &lt; a[r])
              return a[m];
      }
      else
      {
          if(a[p] &lt; a[r])
              return a[p];
          else if(a[m] &gt;= a[r])
              return a[m];
      }
      return a[r];
  }
  </code></pre>