Worksheets › Class 12 › Sorting
Class 12 · Computer Science worksheetSorting
CBSE Computer Science. Bubble, selection and insertion sort pass by pass, swaps, shifts and comparisons, and time complexity. Every sheet has 20 questions in three sections and an answer key, and the questions change every time.
Sample questions
Real questions from this chapter, as the app sets them. Tap Answer to see the answer and working.
Section A · multiple choice
- 1.
In bubble sort, each pass:
- inserts one item into a sorted part
- splits the list in half
- finds the smallest item and swaps it to the front
- compares neighbouring items and swaps those out of order
Answer
(d) 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?
- 39, 40, 58, 36, 27
- 39, 36, 27, 58, 40
- 27, 36, 40, 39, 58
- 39, 36, 27, 40, 58
Answer
(d) 39, 36, 27, 40, 58
each pass compares neighbours left to right and swaps them when out of order; the largest left moves to the end
- 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, 29, 53, 58, 44
- 44, 58, 53, 29, 1
- 1, 29, 58, 53, 44
- 1, 29, 44, 58, 53
Answer
(a) 1, 29, 53, 58, 44
each pass finds the smallest of the unsorted part and swaps it to the front of that part
Section B · short answer
- 4.
Why is sorting useful? Give two examples.
Answer
Sorted data is quicker to search and easier to read, e.g. words in a dictionary, marks ranked from highest, names in a register.
- 5.
Sort 55, 57, 8, 41, 45 into increasing order by bubble sort. Write the list after the second pass, numbers separated by commas.
Answer
8, 41, 45, 55, 57
swaps in each pass: 3, 3
Section C · long answer
- 6.
Write a Python function for bubble sort and explain how it works.
Answer
def 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.
Fresh sheets for your child
In the app, every Sorting sheet is new: the app remembers the questions your child has already had and leaves them out. Print the sheet as a PDF, or use notebook mode and write the answers in a notebook.
Coming soon for Android and iPhone.