Limited access

Upgrade to access all content for this subject

Consider the following method.

public void arrangeArray(int[] nums)
{
    for(int i=0; i< nums.length-1; i++)
    {
        int m = i;       
        for(int j = i+1; j< nums.length; j++)
        {
            if(nums[j] <= nums[m])
                m = j;
        }
        if ( m != i)
        {
            int temp = nums[m];
            nums [m] = nums [i];
            nums [i] = temp;
        }
    }
}

Assume that in each of the listed situations, nums contains 100,000 elements.

For which of the following initial situations for nums would the method perform the fastest?

A

When every element in nums is the same value.

B

When every element in nums is unique and nums is not in any sorted order.

C

When some elements in nums are not unique and nums is sorted in ascending order.

D

When every element in nums is unique and nums is sorted in ascending order.

E

When every element in nums is unique and nums is sorted in descending order.

Select an assignment template