Is this non-recursive mergesort efficient and a good way to simulate the recursive version? My teacher assigned us to do the recursive version of mergesort, yet I heard that the non-recursive version (bottom up) is a bit tougher, so I decided to this one as well. My main concerns are: 


Considering the way I coded it, does it still have the same efficiency?
Did I do this in an acceptable way? If not, why?


Main:

    Random rand = new Random();
    ArrayList&lt;Integer&gt; array = new ArrayList&lt;Integer&gt;();
    for (int i = 0; i &lt; 100; i++){
        array.add(rand.nextInt(20));
    }
    System.out.println("Original:");
    for (int num: array){
        System.out.print(" " + num);
    }
    Algorithm algo = new Algorithm(array);
    algo.print();


Code:

ArrayList&lt;Integer&gt; ar = new ArrayList&lt;Integer&gt;();
int loBound = 0, hiBound = 1;
public Algorithm(ArrayList&lt;Integer&gt; initAr){
    ar = initAr;
    partition();
}
public void partition(){
    if (ar.size() &gt; 1){
        int partitionSize = 1;
        int arraySize = ar.size();

        if (ar.size() % 2 != 0) // if the size is odd make it even so loop doesn't terminate early without sorting all values
            arraySize++;

        while (arraySize / 2 &gt;= partitionSize){
            while (true){
                ArrayList&lt;Integer&gt; left = new ArrayList&lt;Integer&gt;();
                ArrayList&lt;Integer&gt; right = new ArrayList&lt;Integer&gt;();
                // Variables which will be sent to 'update' method as parameters. Tells method which indexes to update (in-between low and high)
                int loInd = loBound, hiInd;
                for (int i = loBound; i &lt; hiBound; i++){
                    left.add(ar.get(i));
                }
                calcBounds(partitionSize);
                for (int j = loBound; j &lt; hiBound; j++){
                    right.add(ar.get(j));
                }
                hiInd = hiBound;
                if (right.size() != partitionSize){
                    update(left, right, loInd, hiInd);
                    break;
                }
                update(left, right, loInd, hiInd);
                calcBounds(partitionSize);
            }
            partitionSize*=2;
            loBound = 0;
            hiBound = partitionSize;
        }
    }
}
// calculates the indexes from which I will extract from the original array
private void calcBounds(int partitionSize){
    if (ar.size() - hiBound &gt; partitionSize){
        loBound = hiBound;
        hiBound = loBound + partitionSize;
    }else {
        loBound = hiBound;
        hiBound = ar.size();
    }
}
// updates original ArrayList after sorting 'left' and 'right'
private void update(ArrayList&lt;Integer&gt; left, ArrayList&lt;Integer&gt; right, int loInd, int hiInd){
    // sort
    ArrayList&lt;Integer&gt; result = new ArrayList&lt;Integer&gt;();
    int lIndex = 0, rIndex = 0, resIndex = 0;
    while (lIndex &lt; left.size() || rIndex &lt; right.size()){
        if (lIndex &lt; left.size() &amp;&amp; rIndex &lt; right.size()){
            if (left.get(lIndex) &lt;= right.get(rIndex)){
                result.add(resIndex, left.get(lIndex));
                resIndex++;
                lIndex++;
            }else {
                result.add(resIndex, right.get(rIndex));
                resIndex++;
                rIndex++;
            }
        }else if (lIndex &lt; left.size()){
            result.add(resIndex, left.get(lIndex));
            resIndex++;
            lIndex++;
        }else if (rIndex &lt; right.size()){
            result.add(resIndex, right.get(rIndex));
            resIndex++;
            rIndex++;
        }
    }
    // update original ArrayList using result ArrayList
    int count = 0;
    for (int i = loInd; i &lt; hiInd; i ++){
        ar.set(i, result.get(count));
        count++;
    }
}

void print(){
    System.out.println();
    System.out.println("Sorted:");
    for (int num: ar){
        System.out.print(" " + num);
    }
}
I have not looked into it too deeply to be able to fully answer your first question. Althought for you to get a picture of efficiency I would suggest to take the normal recursive merge sort and time it using System.nanoTime() and compare it with this version on the same array to be sorted. That could give you a picture about time complexity and regarding memory you would have to use a profiler. Simply jconsole can be enough in this case to see the memory consumption - careful with the GC kicking in when you don't want it.

Second question:
I am not saying that it would be a bad looking code but I have difficulties to understand it. I would suggest few improvements that can help the readability. For example the first one in the method partition - instead of having the whole code block in if (ar.size() > 1) I would suggest having if (ar.size() &lt;= 1) then do return. This gets rid of one level of curly braces for the rest of the code block.

Another suggestion would be to use instance variable as least as possible, in this case loBound = 0, hiBound = 1 and ar. There is a "Brook's law for methods" that says that method should be passed necessary variables as parameters if possible, if not then accessing instance variables and so on. Besides it is some statement it is also improves readability if the method changes only parameters it got passed and not instance variables. You can better track what is being changed and returned in and from the method.

From where I am sitting the main downside of this code would be to come to it half year later and figure out what it does and if it does it right. I would say even the author of the code would have to take some time to figure it out.

I am sorry I might not help you with your first question. Hope the comments on the second one regarding the code style could be of use for you.