Sorting — NCERT Solutions
Assam Board · Class 12 · Computer Science
NCERT Solutions for Sorting, Assam Board Class 12 Computer Science: 6 textbook questions solved step by step. Covers EXERCISE — Chapter: Sorting.
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.
The first 3 solutions are open to read. The other 3 are free with a Super Tutor account.
EXERCISE — Chapter: Sorting (Class 12 Computer Science)
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
Given: numList = [7, 11, 3, 10, 17, 23, 1, 4, 21, 5]
Concept: In Bubble Sort, in each pass we compare adjacent elements and swap them if they are in the wrong order. After pass , the largest elements are placed at the end in their correct positions.
Pass 1:
Start: [7, 11, 3, 10, 17, 23, 1, 4, 21, 5]
- Compare 7, 11 → no swap → [7, 11, 3, 10, 17, 23, 1, 4, 21, 5]
- Compare 11, 3 → swap → [7, 3, 11, 10, 17, 23, 1, 4, 21, 5]
- Compare 11, 10 → swap → [7, 3, 10, 11, 17, 23, 1, 4, 21, 5]
- Compare 11, 17 → no swap → [7, 3, 10, 11, 17, 23, 1, 4, 21, 5]
- Compare 17, 23 → no swap → [7, 3, 10, 11, 17, 23, 1, 4, 21, 5]
- Compare 23, 1 → swap → [7, 3, 10, 11, 17, 1, 23, 4, 21, 5]
- Compare 23, 4 → swap → [7, 3, 10, 11, 17, 1, 4, 23, 21, 5]
- Compare 23, 21 → swap → [7, 3, 10, 11, 17, 1, 4, 21, 23, 5]
- Compare 23, 5 → swap → [7, 3, 10, 11, 17, 1, 4, 21, 5, 23]
After Pass 1: [7, 3, 10, 11, 17, 1, 4, 21, 5, 23]
Pass 2:
Start: [7, 3, 10, 11, 17, 1, 4, 21, 5, 23]
- Compare 7, 3 → swap → [3, 7, 10, 11, 17, 1, 4, 21, 5, 23]
- Compare 7, 10 → no swap → [3, 7, 10, 11, 17, 1, 4, 21, 5, 23]
- Compare 10, 11 → no swap → [3, 7, 10, 11, 17, 1, 4, 21, 5, 23]
- Compare 11, 17 → no swap → [3, 7, 10, 11, 17, 1, 4, 21, 5, 23]
- Compare 17, 1 → swap → [3, 7, 10, 11, 1, 17, 4, 21, 5, 23]
- Compare 17, 4 → swap → [3, 7, 10, 11, 1, 4, 17, 21, 5, 23]
- Compare 17, 21 → no swap → [3, 7, 10, 11, 1, 4, 17, 21, 5, 23]
- Compare 21, 5 → swap → [3, 7, 10, 11, 1, 4, 17, 5, 21, 23]
- Compare 21, 23 → no swap → [3, 7, 10, 11, 1, 4, 17, 5, 21, 23]
After Pass 2: [3, 7, 10, 11, 1, 4, 17, 5, 21, 23]
Pass 3:
Start: [3, 7, 10, 11, 1, 4, 17, 5, 21, 23]
- Compare 3, 7 → no swap → [3, 7, 10, 11, 1, 4, 17, 5, 21, 23]
- Compare 7, 10 → no swap → [3, 7, 10, 11, 1, 4, 17, 5, 21, 23]
- Compare 10, 11 → no swap → [3, 7, 10, 11, 1, 4, 17, 5, 21, 23]
- Compare 11, 1 → swap → [3, 7, 10, 1, 11, 4, 17, 5, 21, 23]
- Compare 11, 4 → swap → [3, 7, 10, 1, 4, 11, 17, 5, 21, 23]
- Compare 11, 17 → no swap → [3, 7, 10, 1, 4, 11, 17, 5, 21, 23]
- Compare 17, 5 → swap → [3, 7, 10, 1, 4, 11, 5, 17, 21, 23]
- Compare 17, 21 → no swap → [3, 7, 10, 1, 4, 11, 5, 17, 21, 23]
After Pass 3: [3, 7, 10, 1, 4, 11, 5, 17, 21, 23]
Final Answer: After three complete passes of Bubble Sort, the partially sorted list is:
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 9Show solution
Given: List = [63, 42, 21, 9]
Bubble Sort
Concept: Compare adjacent elements and swap if out of order. Count swaps and comparisons.
Pass 1: (n−1 = 3 comparisons)
- Compare 63, 42 → swap → [42, 63, 21, 9] — Swap 1
- Compare 63, 21 → swap → [42, 21, 63, 9] — Swap 2
- Compare 63, 9 → swap → [42, 21, 9, 63] — Swap 3
Pass 2: (2 comparisons)
- Compare 42, 21 → swap → [21, 42, 9, 63] — Swap 4
- Compare 42, 9 → swap → [21, 9, 42, 63] — Swap 5
Pass 3: (1 comparison)
- Compare 21, 9 → swap → [9, 21, 42, 63] — Swap 6
Bubble Sort:
- Total Swaps = 6
- Total Comparisons = 6
Selection Sort
Concept: Find the minimum element from the unsorted part and swap it with the first element of the unsorted part.
Pass 1: Find minimum in [63, 42, 21, 9] → min = 9 (index 3)
- Comparisons: 3 (compare 63 with 42, 21, 9)
- Swap 63 and 9 → [9, 42, 21, 63] — Swap 1
Pass 2: Find minimum in [42, 21, 63] → min = 21 (index 2)
- Comparisons: 2
- Swap 42 and 21 → [9, 21, 42, 63] — Swap 2
Pass 3: Find minimum in [42, 63] → min = 42 (index 2)
- Comparisons: 1
- No swap needed (already in place) — Swap 0
Selection Sort:
- Total Swaps = 2
- Total Comparisons = 6
Comparison Table
| Technique | Swaps | Comparisons |
|---|---|---|
| Bubble Sort | 6 | 6 |
| Selection Sort | 2 | 6 |
Conclusion: Both techniques require the same number of comparisons (6). However, Selection Sort is better because it requires only 2 swaps compared to 6 swaps in Bubble Sort. Fewer swaps mean less data movement, making Selection Sort more efficient for this list.
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
Given:
- List 1: [2, 3, 5, 7, 11] (already sorted in ascending order)
- List 2: [11, 7, 5, 3, 2] (sorted in descending order — worst case)
Concept: In Insertion Sort, each element is picked and inserted at its correct position in the already-sorted portion. If the list is already sorted, each new element only needs 1 comparison (with its immediate predecessor). If the list is in reverse order, each new element needs to be compared with all elements in the sorted portion.
List 1: [2, 3, 5, 7, 11] — Already Sorted (Best Case)
| Pass | Element Picked | Sorted Portion | Comparisons | Result |
|---|---|---|---|---|
| 1 | 3 | [2] | 1 (3 > 2, no shift) | [2, 3, 5, 7, 11] |
| 2 | 5 | [2, 3] | 1 (5 > 3, no shift) | [2, 3, 5, 7, 11] |
| 3 | 7 | [2, 3, 5] | 1 (7 > 5, no shift) | [2, 3, 5, 7, 11] |
| 4 | 11 | [2, 3, 5, 7] | 1 (11 > 7, no shift) | [2, 3, 5, 7, 11] |
Total Comparisons for List 1 = 1 + 1 + 1 + 1 = 4
List 2: [11, 7, 5, 3, 2] — Reverse Sorted (Worst Case)
| Pass | Element Picked | Sorted Portion | Comparisons | Result |
|---|---|---|---|---|
| 1 | 7 | [11] | 1 (7 < 11, shift 11) | [7, 11, 5, 3, 2] |
| 2 | 5 | [7, 11] | 2 (5 < 11, 5 < 7, shift both) | [5, 7, 11, 3, 2] |
| 3 | 3 | [5, 7, 11] | 3 (3 < 11, 3 < 7, 3 < 5, shift all) | [3, 5, 7, 11, 2] |
| 4 | 2 | [3, 5, 7, 11] | 4 (2 < 11, 2 < 7, 2 < 5, 2 < 3, shift all) | [2, 3, 5, 7, 11] |
Total Comparisons for List 2 = 1 + 2 + 3 + 4 = 10
Conclusion: List 1 makes the minimum number of comparisons (4) because it is already sorted in ascending order, which is the best case for Insertion Sort. List 2 requires 10 comparisons as it is in reverse order (worst case).
In general:
- Best case complexity of Insertion Sort = → when list is already sorted.
- Worst case complexity of Insertion Sort = → when list is in reverse order.
Free with a Super Tutor account
Steps:
I. Order all values from smallest to largest using Selection Sort.
II. Calculate index by multiplying x percent by the total number of values, n.
III. Ensure that the index is a whole number by using math.round().
IV. Display the value at the index obtained in Step 3.
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 Assam Board Class 12 Computer Science?
Are these NCERT Solutions for Sorting free?
How should I revise Sorting for the Assam Board Class 12 board exam?
Sources & Official References
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 Assam Board Class 12 Computer Science. Free to start, no card needed.