Insertion Sort Algorithm Trace
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
Question Leaderboard
Not enough data yet to show leaderboard.
