Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 6: Array
Start Practice TestPractice Test
About Exam
hard

Selection Sort Swapping Strategy

Mark
< Prev
Next >

The selectionSort method below implements a sorting algorithm. Which statement best describes the effect of its swapping strategy when compared to a classical selection sort?

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

It enhances stability by avoiding unnecessary swaps between equal elements.

B

It reduces overall swap operations by pre-sorting the elements before the main loop.

C

It has no impact on the algorithm’s performance and behaves identically to a standard selection sort.

D

It results in multiple swaps per pass, which can decrease efficiency compared to the single swap in a classical selection sort.

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.

AI Tutor

How can I help?

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