AmbifulWorksheets
Practice that never repeats
CBSE · Class 12 · Computer Science

Sorting

Standard difficulty · 20 questions · 40 marks · Time: 43 minutes

Name: Date: Score: ____ / 40

Show your working for Sections B and C. Answers are on the last page — try every question first!

Section A — Choose the correct answer8 × 1 = 8 marks
1.
In bubble sort, each pass:
  1. inserts one item into a sorted part
  2. splits the list in half
  3. finds the smallest item and swaps it to the front
  4. compares neighbouring items and swaps those out of order
2.
The list 58, 39, 40, 36, 27 is sorted into increasing order by bubble sort. What is the list after the second pass?
  1. 39, 40, 58, 36, 27
  2. 39, 36, 27, 58, 40
  3. 27, 36, 40, 39, 58
  4. 39, 36, 27, 40, 58
3.
The list 29, 1, 53, 58, 44 is sorted into increasing order by selection sort. What is the list after the second pass?
  1. 1, 29, 53, 58, 44
  2. 44, 58, 53, 29, 1
  3. 1, 29, 58, 53, 44
  4. 1, 29, 44, 58, 53
4.
The list 52, 25, 48, 33, 41, 5 is sorted into increasing order by insertion sort. What is the list after the third pass (pass 1 places the second item)?
  1. 25, 33, 48, 52, 41, 5
  2. 33, 25, 48, 52, 41, 5
  3. 25, 48, 33, 52, 41, 5
  4. 5, 25, 33, 48, 41, 52
5.
How many swaps does the first pass of bubble sort make on 57, 42, 46, 37, 20?
  1. 9
  2. 5
  3. 3
  4. 4
6.
How many comparisons does the textbook's bubble sort make in all to sort a list of 15 numbers (it does not stop early)?
  1. 210
  2. 105
  3. 225
  4. 14
7.
What does this print?
L = [58, 38, 36, 32, 8, 28]
n = len(L)
for i in range(1, 4):
    t = L[i]
    j = i - 1
    while j >= 0 and t < L[j]:
        L[j + 1] = L[j]
        j = j - 1
    L[j + 1] = t
print(L)
  1. [32, 36, 38, 58, 8, 28]
  2. [36, 32, 38, 58, 8, 28]
  3. [32, 36, 38, 8, 58, 28]
  4. [32, 36, 58, 38, 8, 28]
8.
A list 34, 52, 2, 37, 15, 50, 9 becomes 34, 2, 37, 15, 50, 9, 52 after the first pass and 2, 34, 15, 37, 9, 50, 52 after the second. Which sort is being used?
  1. selection sort
  2. merge sort
  3. bubble sort
  4. binary search
Section B — Short answer8 × 2 = 16 marks
9.
Why is sorting useful? Give two examples.
10.
Sort 55, 57, 8, 41, 45 into increasing order by bubble sort. Write the list after the second pass, numbers separated by commas.
11.
Sort 31, 46, 35, 17, 36, 26, 43 into increasing order by selection sort. Write the list after the second pass, numbers separated by commas.
12.
Sort 52, 42, 33, 45, 31, 59, 26 into increasing order by insertion sort. Write the list after the second pass (pass 1 places the second item), numbers separated by commas.
13.
How many swaps in all does bubble sort make to sort 19, 54, 18, 1, 3 into increasing order?
14.
What does this print?
L = [42, 57, 39, 30, 52]
n = len(L)
for i in range(1, 3):
    t = L[i]
    j = i - 1
    while j >= 0 and t < L[j]:
        L[j + 1] = L[j]
        j = j - 1
    L[j + 1] = t
print(L)
15.
Bubble sort is used to arrange 59, 13, 17, 45, 32, 30 in increasing order. Write the list after the second pass, numbers separated by commas.
16.
How many times does insertion sort shift an item one place to the right while sorting 36, 43, 3, 54, 19, 21 into increasing order?
Section C — Word problems4 × 4 = 16 marks
17.
Write a Python function for bubble sort and explain how it works.
18.
Sort 59, 52, 7, 29, 45, 46 into increasing order by bubble sort, showing the list after every pass. (a) Write the list after each pass. (b) How many swaps are made in each pass? (c) After which pass is the list first fully sorted?
19.
Sort 29, 12, 28, 54, 47, 31 into increasing order (a) by selection sort and (b) by insertion sort, writing the list after every pass.
20.
(a) What does this program print? (b) Which sorting method is it? (c) How many passes are still needed, at most, to finish sorting the list?
L = [42, 18, 58, 32, 24]
n = len(L)
for i in range(1):
    for j in range(0, n - i - 1):
        if L[j] > L[j + 1]:
            L[j], L[j + 1] = L[j + 1], L[j]
print(L)
AmbifulWorksheets
Practice that never repeats
CBSE · Class 12 · Computer Science

Answer key

Sorting · AW-12CS-SRT-2026-V1 · For parents — fold back or tear off before handing the sheet to your child.

QAnswerWorking
1(d) compares neighbouring items and swaps those out of order—
2(d) 39, 36, 27, 40, 58each pass compares neighbours left to right and swaps them when out of order; the largest left moves to the end
3(a) 1, 29, 53, 58, 44each pass finds the smallest of the unsorted part and swaps it to the front of that part
4(a) 25, 33, 48, 52, 41, 5pass i takes the item at index i and shifts the larger items on its left one place right
5(d) 4compare each neighbouring pair once, left to right, swapping as you go
6(b) 10514 + 13 + … + 1 = 15 × 14 ÷ 2
7(a) [32, 36, 38, 58, 8, 28]insertion sort for 3 passes
8(c) bubble sortbubble sort moves the largest to the end each pass
9Sorted data is quicker to search and easier to read, e.g. words in a dictionary, marks ranked from highest, names in a register.—
108, 41, 45, 55, 57swaps in each pass: 3, 3
1117, 26, 35, 31, 36, 46, 43each pass swaps the smallest of the unsorted part to its front
1233, 42, 52, 45, 31, 59, 26pass i inserts the item at index i into the sorted part on its left
138swaps in each pass: 3, 3, 2, 0, 0 (each swap fixes one out-of-order pair)
14[39, 42, 57, 30, 52]insertion sort for 2 passes
1513, 17, 32, 30, 45, 59swap when the left item is larger
168the shifts equal the number of out-of-order pairs; sorted: 3, 19, 21, 36, 43, 54
17def bubble(L): n = len(L); for i in range(n): for j in range(0, n − i − 1): if L[j] > L[j + 1]: L[j], L[j + 1] = L[j + 1], L[j]. Each pass compares neighbours and swaps those out of order; after pass i the i largest items are in place at the end.—
18(a) 52, 7, 29, 45, 46, 59 → 7, 29, 45, 46, 52, 59 → 7, 29, 45, 46, 52, 59 → 7, 29, 45, 46, 52, 59 → 7, 29, 45, 46, 52, 59; (b) 5, 4, 0, 0, 0; (c) pass 2the largest unsorted item reaches its place at the end of each pass
19(a) 12, 29, 28, 54, 47, 31 → 12, 28, 29, 54, 47, 31 → 12, 28, 29, 54, 47, 31 → 12, 28, 29, 31, 47, 54 → 12, 28, 29, 31, 47, 54; (b) 12, 29, 28, 54, 47, 31 → 12, 28, 29, 54, 47, 31 → 12, 28, 29, 54, 47, 31 → 12, 28, 29, 47, 54, 31 → 12, 28, 29, 31, 47, 54selection: swap the smallest of the rest to the front; insertion: insert the next item into the sorted left part
20(a) [18, 42, 32, 24, 58]; (b) bubble sort; (c) 3a list of 5 items needs at most 4 passes