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
medium Solved by 1 students

Insertion Sort Algorithm Trace

Mark
< Prev
Next >

Consider the following code segment, which applies an insertion sort to the data array.

int[] data = {30, 15, 40, 10, 25};
for (int i = 1; i < data.length; i++) {
    int key = data[i];
    int j = i - 1;
    while (j >= 0 && data[j] > key) {
        data[j + 1] = data[j];
        j--;
    }
    data[j + 1] = key;
}

What is the value of data[1] after the outer loop completes its third iteration (when i = 3)?

A

30

B

25

C

10

D

15

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|