Core9X
Log inSign up

MBOSE Class XII Computer Science · Chapter 5

Sorting

Opening soon

How bubble, selection and insertion sort put data in order, and how Big-O notation compares how fast they run.

14 lessons · 56 practice questions · unit "Computational Thinking and Programming" carries 40 marks

See classes open nowLog inMBOSE Class XII opens to new students soon.

What this chapter covers

  • Sorting
  • Bubble sort
  • Selection sort
  • Insertion sort — algorithms, passes and Python programs
  • Time complexity — constant, linear and quadratic time
  • Big-O notation

Key terms

Sorting

Arranging elements in a particular order

Pass

One complete traversal of the (unsorted part of the) list

Swap

Exchanging two elements

Bubble sort

Sorting by swapping adjacent elements

Selection sort

Sorting by selecting the minimum of the unsorted part

Insertion sort

Sorting by inserting each element into the sorted part

Time complexity

Time taken as a function of input size

Big-O notation

Upper bound of an algorithm's growth rate

Important questions with answers

10 of the 56 questions on this chapter, solved.

  1. Question 1 · Multiple choice · 1 mark

    Sorting means

    • (a) arranging elements in a particular order
    • (b) searching for an element
    • (c) deleting duplicates
    • (d) counting elements

    Answer: (a) arranging elements in a particular order

    Ascending or descending.

  2. Question 2 · Multiple choice · 1 mark

    How many comparisons does bubble sort make for 4 elements without early stopping?

    • (a) 4
    • (b) 3
    • (c) 16
    • (d) 6

    Answer: (d) 6

    3 + 2 + 1.

  3. Question 3 · Multiple choice · 1 mark

    The maximum number of swaps in selection sort for n elements is

    • (a) n − 1
    • (b) n²
    • (c) n
    • (d) 2n

    Answer: (a) n − 1

    At most one swap per pass.

  4. Question 4 · Multiple choice · 1 mark

    A single loop over n elements gives

    • (a) linear time, O(n)
    • (b) O(1)
    • (c) O(n²)
    • (d) O(log n)

    Answer: (a) linear time, O(n)

    The body runs n times.

  5. Question 5 · Assertion and reason · 1 mark

    Assertion (A): After the first pass of bubble sort, the largest element is at the end.

    Reason (R): Adjacent elements are swapped whenever the left one is larger.

    • (a) Both A and R are true, and R is the correct explanation of A.
    • (b) Both A and R are true, but R is not the correct explanation of A.
    • (c) A is true, but R is false.
    • (d) A is false, but R is true.

    Answer: (a) Both A and R are true, and R is the correct explanation of A.

    The largest keeps moving right.

  6. Question 6 · Short answer · 2 marks

    What is a pass in sorting?

    Answer

    One traversal of the (unsorted part of the) list, comparing and possibly swapping elements.

  7. Question 7 · Short answer · 2 marks

    What is constant time?

    Answer

    Time that does not change with input size, O(1).

  8. Question 8 · Short answer · 3 marks

    Show insertion sort on [12, 11, 13, 5, 6].

    Answer

    [11, 12, 13, 5, 6] → same → [5, 11, 12, 13, 6] → [5, 6, 11, 12, 13].

  9. Question 9 · Long answer · 5 marks

    Explain bubble sort with an example and a program.

    Answer

    Section 1.2; Exercise Q1.

  10. Question 10 · Long answer · 5 marks

    Explain insertion sort with an example and a program.

    Answer

    Section 1.4; Exercise Q3 and Q6.

Study the whole chapter

14 step-by-step lessons, all 56 practice questions with hints, flashcards and mock tests for MBOSE Class XII Computer Science.

See classes open nowLog inMBOSE Class XII opens to new students soon.
Sorting: MBOSE Class 12 Computer Science notes, important questions and answers · Core9X