Computer Science · Class 12 Optional
Ch 5Sorting — Class 12 Computer Science, concept-first.
Sorting is the process of arranging a given collection of elements in a specific order. This order can be ascending or descending for numbers, or alphabetical for strings. The core idea is to bring order to a set of items so that they become easier to work with.
12
Q&A
6
Concepts
40m
Section weightage
Computational Thinking and Programming – 2 · across all 7 lessons
Key concepts
Hover a concept to preview it and jump to its most relevant Q&A.
Bubble Sort Modification
Imagine you have a messy pile of exam answer sheets and you want to arrange them in order of roll numbers. One simple way is to walk through the pile from top to bottom, and whenever you find two adjacent sheets that are…
Most relevant Q&A
- Algorithm 5.1 sorts a list in ascending order. Write a bubble sort algorithm to sort a list in descending order?Preview
- Apply bubble sort technique to sort a list of elements numList2 = [8, 7, 6, 5, 4]. Show the positions of elements in the list after each pas…Preview
- In Figure 5.1, we can see that the list got sorted in the 4th pass itself. Still the bubble sort technique made a redundant 5th pass which d…Preview
Chapter contents
The NCERT structure, section by section. Open a section to see its questions, then read the concept-first solution.
Introduction
Sorting is the process of arranging a given collection of elements in a specific order. This order can be ascending or descending for numbers, or alphabetical for strings.
+−Think & Reflect1 question
Bubble Sort
3 QBubble sort works by repeatedly stepping through a list, comparing adjacent elements, and swapping them if they are in the wrong order.
+−Activities1 question
+−Activities1 question
Selection Sort
Selection sort works on a simple idea: repeatedly pick the smallest element from the unsorted part of the list and put it at the beginning.
Insertion Sort
Insertion sort is a sorting algorithm that builds the final sorted list one element at a time. Like selection sort, it divides the list into two parts: a sorted section and an unsorted section.
Time Complexity of Algorithms
When you write a program to solve a problem, there is often more than one way to do it. You saw this in Class XI when you compared four different algorithms to check whether a given number is prime.
Summary
- Sorting: The process of arranging a collection of elements in a particular order — ascending or descending for numbers, alphabetical for strings — making the elements easier to search and retrieve.
Exercises
+−Show 6 questionsHide questions6 questions
- Q1Consider 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…Free
- Q2Identify the number of swaps required for sorting the following list using selection sort and bubble sort and identify which is the better s…Free
- Q3Consider the following lists: | List 1: | 2 | 3 | 5 | 7 | 11 | |---------|---|---|---|---|----| | List 2: | 11 | 7 | 5 | 3 | 2 | |---------|…Preview
- Q4Write a program using user defined functions that accepts a List of numbers as an argument and finds its median. (Hint : Use bubble sort to…Preview
- Q5All the branches of XYZ school conducted an aptitude test for all the students in the age group 14 - 16. There were a total of n students. T…Preview
- Q6During admission in a course, the names of the students are inserted in ascending order. Thus, performing the sorting operation at the time…Preview