Please enable JavaScript to use CodeHS

Want to receive Question of the Day updates? Subscribe Here

AP CSA Question of the Day April 18, 2025

Reference
  1. Incorrect Correct No Answer was selected Invalid Answer

    Consider the following correct implementation of the selection sort algorithm:

    public static ArrayList<Integer> selectionSort(ArrayList<Integer> arr)
    {
        int currentMinIndex;
    
        for (int i = 0; i < arr.size() - 1; i++)
        {
            currentMinIndex = i;
            for (int j = i + 1; j < arr.size(); j++)
            {
                if(arr.get(j) < arr.get(currentMinIndex))
                {
                    currentMinIndex = j;  //Line 12
                }
            }
            if (i != currentMinIndex)
            {
                int temp = arr.get(currentMinIndex);
                arr.set(currentMinIndex, arr.get(i));
                arr.set(i, temp); 
            }
        }
        return arr;
    }
    Java

    Given an ArrayList initialized with the values [14, 12, 1, 6, 3, 10], how many times does Line 12 execute when the ArrayList is sorted using the selection sort algorithm?