title: A program that finds the Kth largest element in a list
body: <p>Am writing a logic program for kth_largest(Xs,K) that implements the linear algorithm for finding the
  kth largest element K of a list Xs. The algorithm has the following steps:</p>
  
  <ol>
  <li>Break the list into groups of five elements.</li>
  <li>Efficiently find the median of each of the groups, which can be done with a fixed number of
  comparisons.</li>
  <li>Recursively find the median of the medians.</li>
  <li>Partition the original list with respect to the median of the medians.</li>
  <li>Recursively find the kth largest element in the appropriate smaller list.</li>
  </ol>
  
  <p>How do I go about it? I can select an element from a list but I don't know how to get the largest using the above procedure.Here is my definition for selecting an element from a list</p>
  
  <pre><code>select(X; HasXs; OneLessXs)  
  % The list OneLessXs is the result of removing
  % one occurrence of X from the list HasXs.
  select(X,[X|Xs],Xs).
  select(X,[Y|Ys],[Y|Zs]) :-  select(X,Ys,Zs).
  </code></pre>