Skip to content

Ch 5 · Sorting

In-text Questions

Exercise 2 of 3
Question 1NCERT PDF page 12
• Any algorithm that does not have any loop will have
time complexity as 1 since the number of instructions
to be executed will be constant, irrespective of the
data size. Such algorithms are known as Constant
time algorithms.
Answer

State the algorithm or concept, trace the logic step by step, and provide syntactically correct code, SQL or output where requested.

Check: Verify the result for the stated input and mention the relevant constraint or complexity.

Question 2NCERT PDF page 12
• Any algorithm that has a loop (usually 1 to n) will
have the time complexity as n because the loop will
execute the statement inside its body n number of
times. Such algorithms are known as Linear time
algorithms.
Answer

State the algorithm or concept, trace the logic step by step, and provide syntactically correct code, SQL or output where requested.

Check: Verify the result for the stated input and mention the relevant constraint or complexity.

Question 3NCERT PDF page 12
• A loop within a loop (nested loop) will have the time
complexity as n2. Such algorithms are known as
Quadratic time algorithms.
Answer

State the algorithm or concept, trace the logic step by step, and provide syntactically correct code, SQL or output where requested.

Check: Verify the result for the stated input and mention the relevant constraint or complexity.

Question 4NCERT PDF page 12
• If there is a nested loop and also a single loop, the
time complexity will be estimated on the basis of the
nested loop only.
Now, look at the Python programs of the three sorting
techniques discussed in this chapter, you will notice that
in each of the three programs, there is a nested loop,
i.e., one inside another. So according to the above rules,
all the sorting algorithms namely, bubble sort, selection
sort and insertion sort have a time complexity of n2.
Answer

State the algorithm or concept, trace the logic step by step, and provide syntactically correct code, SQL or output where requested.

Check: Verify the result for the stated input and mention the relevant constraint or complexity.