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
Marked for reviewAbout Exam
medium Solved by 11 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 inner loop’s boundary calculation fails to account for the ‘start’ index, leading to incorrect sorting of the specified segment.

B

The algorithm does not perform swaps when elements are equal.

C

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

D

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

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
#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
#7elieafram13 13m 33s -733
#8geethasailaja11 20m 08s -1,108
#9sathilak00013 23m 00s -1,300
#10singhris00012 26m 25s -1,495
Items per page:
10
1 – 10 of 10
No comments yet. Be the first to comment!

AI Tutor

How can I help?

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