title: QuickSelect Algorithm Understanding
body: <p>I've been poring over various tutorials and articles that discuss quicksort and quickselect, however, my understanding of them is still shaky.</p>
  <p>Given this code structure, I need to be able to grasp and explain how quickselect works.</p>
  <pre><code>// return the kth smallest item
  int quickSelect(int items[], int first, int last, int k) {
      int pivot = partition(items, first, last);
      if (k &lt; pivot-first) {
          return quickSelect(items, first, pivot, k);
      } else if (k &gt; pivot) {
          return quickSelect(items, pivot+1, last, k-pivot);
      } else {
          return items[k];
      }
  }
  </code></pre>
  <p>I need a little help with breaking down into pseudo-code, and while I haven't been provided with the partition function code, I'd like to understand what it would do given the quickselect function provided.</p>
  <p>I know how quicksort works, just not quickselect. The code I just provided is an example we were given on how to format quick select.</p>
  <p>EDIT: The corrected code is</p>
  <pre><code>int quickSelect(int items[], int first, int last, int k) 
  {
      int pivot = partition(items, first, last);
      if (k &lt; pivot-first+1) 
      { //boundary was wrong
          return quickSelect(items, first, pivot, k);
      } 
      else if (k &gt; pivot-first+1) 
      {//boundary was wrong
          return quickSelect(items, pivot+1, last, k-pivot);
      }
      else 
      {
          return items[pivot];//index was wrong
      }
  }
  </code></pre>