Sorting — NCERT Solutions
CBSE · Class 12 · Computer Science
NCERT question answers for Sorting, CBSE Class 12 Computer Science: 6 textbook questions solved step by step. Covers Exercise.
Interactive on Super Tutor
Studying Sorting? Get the full interactive chapter.
Quizzes, flashcards, AI doubt-solver and a step-by-step study plan — built for NCERT solutions and more.
Free trial, no card needed.

Learn better with visuals Super Tutor pairs illustrations like this with notes and quizzes for Sorting.
Get startedThe first 3 solutions are open to read. The other 3 are free with a Super Tutor account. Unlock all 6 free in Super Tutor
Exercise
1Consider a list of 10 elements:
numList = [7, 11, 3, 10, 17, 23, 1, 4, 21, 5].
Display the partially sorted list after three complete passes of Bubble sort.Show solution
Use Bubble Sort on the list
.
- Pass 1: largest element moves to the end.
Result:
- Pass 2: next largest moves to its position.
Result:
- Pass 3: next largest moves to its position.
Result:
So after three complete passes, the partially sorted list is:
.
Not sure why a step works? check your working in Super Tutor
2Identify the number of swaps required for sorting the following list using selection sort and bubble sort and identify which is the better sorting technique with respect to the number of comparisons.List 1 : 63 42 21 9
Show solution
| List 1 : | 63 | 42 | 21 | 9 |
|---|
For the list [63, 42, 21, 9]:
- Selection sort makes n - 1 = 3 passes.
- In each pass, it finds the smallest element from the unsorted part and swaps it into place.
Selection sort swaps
- Pass 1: smallest is 9 → swap with 63
[9, 42, 21, 63]
- Pass 2: smallest in remaining list is 21 → swap with 42
[9, 21, 42, 63]
- Pass 3: remaining elements are already in order, so no swap needed.
So, selection sort requires 2 swaps.
Bubble sort swaps
Bubble sort swaps adjacent elements whenever they are out of order.
For a list in descending order, every adjacent comparison causes a swap until the list becomes sorted.
For 4 elements, the number of swaps needed is:
- Pass 1: 3 swaps
- Pass 2: 2 swaps
- Pass 3: 1 swap
Total swaps = 3 + 2 + 1 = 6
So, bubble sort requires 6 swaps.
Better technique with respect to comparisons
From the chapter, both selection sort and bubble sort use nested loops and have time complexity, so for this small list both make the same order of comparisons. However, selection sort is better with respect to swaps, and in this case it also uses fewer swaps than bubble sort.
Thus, the better sorting technique here is selection sort.
Not sure why a step works? check your working in Super Tutor
3Consider the following lists:List 1: 2 3 5 7 11
List 2: 11 7 5 3 2
If the lists are sorted using Insertion sort then which of the lists List1 or List 2 will make the minimum number of comparisons? Justify using diagrammatic representation.
Show solution
| List 1: | 2 | 3 | 5 | 7 | 11 |
|---|
| List 2: | 11 | 7 | 5 | 3 | 2 |
|---|
If the lists are sorted using Insertion sort then which of the lists List1 or List 2 will make the minimum number of comparisons? Justify using diagrammatic representation.
For Insertion sort, the number of comparisons depends on how ordered the list already is.
List 1: [2, 3, 5, 7, 11]
This list is already in ascending order.
- In each pass, the next element is already in the correct place.
- So insertion sort makes the minimum number of comparisons.
List 2: [11, 7, 5, 3, 2]
This list is in descending order.
- Every new element must be compared with all the elements in the sorted part.
- So it makes the maximum number of comparisons.
Justification
- List 1 → best case for insertion sort → minimum comparisons
- List 2 → worst case for insertion sort → more comparisons
Therefore, List 1 will make the minimum number of comparisons.
Diagrammatically:
- List 1:
2 | 3 | 5 | 7 | 11→ already sorted, so each next element stays in place. - List 2:
11 | 7 | 5 | 3 | 2→ each element must move left across the sorted part.
Not sure why a step works? check your working in Super Tutor
Free with a Super Tutor account
Note: Percentile is a measure of relative performance i.e. It is calculated based on a candidate's performance with respect to others. For example : If a candidate's score is in the 90 percentile, that means she/he scored better than 90% of people who took the test.
Steps to calculate the x percentile:
I. Order all the values in the data set from smallest to largest using Selection Sort. In general any of the sorting methods can be used.
II. Calculate index by multiplying x percent by the total number of values, n.
For example: to find 90 percentile for 120 students:
III. Ensure that the index is a whole number by using math.round()
IV. Display the value at the index obtained in Step 3.
The corresponding value in the list is the x percentile.
Free with a Super Tutor account
Free with a Super Tutor account
3 more solved questions in Sorting
They are free with a Super Tutor account, along with practice quizzes and flashcards for this chapter. Free to start, no card needed.
Frequently Asked Questions
What are the important topics in Sorting for CBSE Class 12 Computer Science?
Are these NCERT Solutions for Sorting free?
How should I revise Sorting for the CBSE Class 12 board exam?
Sources & Official References
- NCERT Official — ncert.nic.in
- CBSE Academic — cbseacademic.nic.in
- CBSE Official — cbse.gov.in
- National Education Policy 2020 — education.gov.in
Content is aligned to the official syllabus. Refer to the board website for the latest curriculum.
More resources for Sorting
Practice Quiz
Test yourself with a quick quiz
Important Questions
Exam-style questions with answers
Revision Notes
Key points for last-minute revision
Formula Sheet
The chapter's formulas in one place
Chapter Summary
Understand the chapter at a glance
Concept Maps
See how topics connect
Study Plan
Step-by-step plan for this chapter
Flashcards
Quick-fire cards for active recall
Syllabus
What topics to cover
For serious students
Get the full Sorting chapter — start free.
Quizzes, flashcards, an AI doubt solver and a study plan for CBSE Class 12 Computer Science. Free to start, no card needed.