Consider the code given below, which runs insertion sort: void…

PYQ CoCubes 2024

Consider the code given below, which runs insertion sort:

void insertionSort(int arr[], int array_size)

{

int i, j, value;

for (i = 1; i < array_size; i++)

{

value = arr[i];

j = i;

while (________ )

{

arr[j] = arr[j − 1];

j = j − 1;

}

arr[j] = value;

}

}

Which condition will correctly implement the while loop?

  1. A.

    (j > 0) || (arr[j − 1] > value)

  2. B.

    (j > 0) && (arr[j − 1] > value)

  3. C.

    (j > 0) && (arr[j + 1] > value)

  4. D.

    (j > 0) && (arr[j + 1] < value)

Attempted by 274 students.

Sign up free to check your answer

Sign up free

Explore the full course: Cdac C Cat Complete Preparation

Loading lesson…