Choosing how to earn college credit? CLEP vs AP guide
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 4: Data Collections
Start Practice TestPractice Test
About Exam
hard Solved by 1 students

Selection Sort Algorithm Stability

Mark
< Prev
Next >

The selectionSort method shown below implements the selection sort algorithm. Which of the following statements best describes the stability of this algorithm when used to sort an array of objects based on a key field?

public class SelectionSort {
    public static void selectionSort(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            int minIndex = i;
            for (int j = i+1; j < arr.length; j++) {
                if (arr[j] < arr[minIndex])
                    minIndex = j;
            }
            int temp = arr[minIndex];
            arr[minIndex] = arr[i];
            arr[i] = temp;
        }
    }
}
A

Selection sort is not stable because it may swap non-adjacent elements, disrupting the original order of equal keys.

B

Selection sort is stable only when sorting primitive int types.

C

Selection sort is stable because it preserves the order of equal elements.

D

The stability of selection sort depends on the implementation of the swap operation.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Instagram: @_apfive_|Privacy Policy|