| preferred AP College board partner for AP classes
AP Computer Science A/Unit 6: Array
Start Practice TestPractice Test
About Exam
medium Solved by 13 students
Logical Error In Partial Bubble Sort
< Prev
Next >

The following bubbleSortPartial method is intended to sort a segment of an array. Which statement best describes the logical error in the method?

public class BubbleSortPartial {
    public static void bubbleSortPartial(int[] arr, int start, int end) {
         for (int i = start; i < end; i++) {
             for (int j = start; j < end - i - 1; j++) {
                 if (arr[j] > arr[j+1]) {
                     int temp = arr[j];
                     arr[j] = arr[j+1];
                     arr[j+1] = temp;
                 }
             }
         }
    }
}
A

The algorithm does not perform swaps when elements are equal.

B

There is an off-by-one error in the outer loop’s termination condition.

C

The inner loop’s boundary calculation fails to account for the ‘start’ index, leading to incorrect sorting of the specified segment.

D

The outer loop should begin at index 0 regardless of the start parameter.

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1bommasam00033 2m 32s 148
#2the.ronzono11 0m 00s 100
#3y.seong202711 1m 10s 30
#4kazvin.tjakradinata13 1m 34s -14
#5winstonhou110712 2m 49s -79
#6suhanakochhar00611 3m 16s -96
#7geethasailaja11 20m 08s -1,108
#8sathilak00013 23m 00s -1,300
#9singhris00012 26m 25s -1,495
Items per page:
10
1 – 9 of 9
No comments yet. Be the first to comment!

AI Tutor

How can I help?

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