?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Run Time Analysis of Two Methods with an ArrayList Returned

APCSA-1G6LDV

Consider the following methods:

public static ArrayList<Integer> multiplyByN1(int n, int s)
{
    ArrayList<Integer> nums = new ArrayList<Integer>();
    for (int i=1; i<=s; i++)
    {
        nums.add(0,i*n);
    }
    return nums;
}

public static ArrayList<Integer> multiplyByN2(int n, int s)
{
    ArrayList<Integer> nums = new ArrayList<Integer>();
    for (int i=1; i<=s; i++)
    {
        nums.add(i*n);
    }
    return nums;
}

Which of the following statements is true when comparing these two methods and passing them the same parameters?

I. multiplyByN1 will produce a different result than multiplyByN2.
II. multiplyByN1 will produce the same result as multiplyByN2.
III. multiplyByN1 has a longer run time than multiplyByN2.
IV. multiplyByN2 has a longer run time than multiplyByN1.
V. The for loops in multiplyByN1 and multiplyByN2 will iterate a different number of times.

A

I and III only

B

I and IV only

C

II and III only

D

II and IV only

E

I, IV, and V only