Java sort by selection: which is better in regards to readability and efficiency? Which algorithm do you think is better in regards to readability and efficiency?

selection():

public static int[] selection(int[] tab) {
    int minor;
    int aux;
    for (int i=0; i&lt;tab.length-1; i++) {
        minor = tab[i];
        for (int j=i+1; j&lt;=tab.length-1; j++) {
            if (tab[j] &lt; minor) {
                aux = tab[j];
                tab[j] = minor;
                minor = aux;
            }
        }
        tab[i] = minor;
    }
    return tab;
}


otherSelection():

public static int[] otherSelection(int A[]) {
    int i, j, minor, pos, tmp;
    for (i = 0; i &lt; A.length - 1; i++) {
        minor = A[i]; 
        pos = i;
        for (j = i + 1; j &lt; A.length; j++){
            if (A[j] &lt; minor) {
                minor = A[j]; 
                pos = j;
            }
        }
        if (pos != i){
            tmp = A[i];
            A[i] = A[pos];
            A[pos] = tmp;
        }
    }
    return A;
}
Readability:

The first one is far more readable because it can be translated at so:

selection(tab) 
    for each value of tab: i = (0-&gt;size-1) 
        minor = tab[i]
        for each value of tab: j = (i-&gt;size-1) 
            if (tab[j] &lt; minor) 
                swap(minor, tab[j])
        tab[i] = minor;
    return tab;


This is very simple and symmetric.  The otherSelection is a bit more difficult to read because it tracks a pos.  This is a uncommon way to do this sort (not necessarily bad).  Then it does the swap post inner loop.  This was personally more difficult for me to read.  The first wins here.

Time Efficiency:

Both run \$O(n^2)\$.  However, otherSelection does only swap once per n-iteration.  This actually is more efficient to do.

Space Efficiency:

selection only needs 4 int variables where as otherSelection needs 5.  It's a bit more space efficient to use selection.  As user @200_success mentioned, the space efficiency is the same at worse case since both are constant space \$O(1)\$.  This isn't counting the input space (which you shouldn't really anyways).

Final verdict:

selection is a better option than otherSelection as far as readability.  However, otherSelection is better for efficiency.  This is a better variant of otherSelection which is just as good when it comes to space efficiency:

public static void selectionSort2(int[] x) {
    for (int i=0; i&lt;x.length-1; i++) {
        int minIndex = i;      // Index of smallest remaining value.
        for (int j=i+1; j&lt;x.length; j++) {
            if (x[minIndex] &gt; x[j]) {
                minIndex = j;  // Remember index of new minimum
            }
        }
        if (minIndex != i) { 
            //...  Exchange current element with smallest remaining.
            int temp = x[i];
            x[i] = x[minIndex];
            x[minIndex] = temp;
        }
    }
}


If you care for efficiency, this is the better selection sort option.  You could also do a bit-swap for when swapping the variables.  

Final notes:  Since this is Java, you don't need to do the return statement at the end.