PRASHNIKAप्रश्निका
‹ Back to the paper

The following program code sorts a single dimensional array in ascending order using Insertion Sort…

Computer Science20221 markMCQ
The following program code sorts a single dimensional array in ascending order using Insertion Sort technique. There are some places in the code marked as ?1?, ?2?, ?3?, ?4? and ?5? which are to be replaced by a statement/expression so that the code works properly.
void insertionSort(int array[])
{
    int n = ?1?;
    for (int j = 1; j < n; j++)
    {
        int key = ?2?;
        int i = j - 1;
        while ((i > -1) && (array[i] > ?3?))
        {
            array[i + 1] = ?4?;
            i--;
        }
        ?5? = key;
    }
}
What is the statement or expression at ?1?
  • (i)array.length()
  • (ii)array.length
  • (iii)length
  • (iv)-1

Answer

No answer yet.

Implementation of algorithms to solve problems

From ISC 2022 Computer Science - Specimen paper (Semester 1), Paper 1, question 32(a).