Consider the following code snippet, which implements the Shell sort algorithm.
shellSort( int elements[], int num_elements , int incrmnts[], int num_incrmnts)
{
int incr, j, k, span, y;
for(incr = 0; incr ;< num_incrmnts; incr++)
{
span = incrmnts[incr]; data-structure-questions-answers-shell-sort
for( j = span; j < num_elements; j++)
{
k = j;
y = elements[j];
while (________ )
{
elements [ k] = elements[k - span];
k = k - span;
}
elements[k] = y;
}
}
Which condition will correctly implement the while loop?
shellSort( int elements[], int num_elements , int incrmnts[], int num_incrmnts)
{
int incr, j, k, span, y;
for(incr = 0; incr ;< num_incrmnts; incr++)
{
span = incrmnts[incr]; data-structure-questions-answers-shell-sort
for( j = span; j < num_elements; j++)
{
k = j;
y = elements[j];
while (________ )
{
elements [ k] = elements[k - span];
k = k - span;
}
elements[k] = y;
}
}A. k >= j && y < elements[k- span]
B. k >= j && y < elements[k- span]
C. k >= j || y < elements[k + span]
D. k >= span && y < elements[k- span]
Answer: Option D

Join The Discussion