Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
medium Solved by 3 students

Stability of Overloaded Bubble Sort Methods

< Prev
Next >

Consider the BubbleSorter class, which contains two overloaded sort methods. Which statement correctly describes the stability of these sorting algorithms?

public class BubbleSorter {
    public void sort(int[] arr) {
        for(int i = 0; i < arr.length; i++) {
            for(int j = 0; j < arr.length - 1; j++) {
                if(arr[j] > arr[j+1]) {
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
    }
    
    public void sort(double[] arr) {
        for(int i = 0; i < arr.length; i++) {
            for(int j = 0; j < arr.length - 1; j++) {
                if(arr[j] > arr[j+1]) {
                    double temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
    }
}
A

Both methods may become unstable when sorting objects, but for primitive types, stability is not a concern.

B

Only the integer sort method is stable, while the double sort method is not due to floating-point precision issues.

C

Both methods are stable because they only swap elements when necessary, preserving the order of equal elements.

D

The overloaded methods create ambiguity during sorting, making it unclear which method maintains order correctly.

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Total Time
Score
#1chunxiangxu.cxu23 0m 27s 163
#2suhanakochhar00611 1m 02s 38
#3zgj0731041701 0m 44s -54
#4y.seong202711 9m 54s -494
Items per page:
10
1 – 4 of 4
No comments yet. Be the first to comment!

AI Tutor

How can I help?

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