Please refer to Sorting Class 11 Computer Science notes and questions with solutions below. These revision notes and important examination questions have been prepared based on the latest Computer Science books for Class 11. You can go through the questions and solutions below which will help you to get better marks in your examinations.
Class 11 Computer Science Sorting Notes and Questions
To arrange the elements in ascending or descending order.
In this chapter we shall discuss two sorting techniques:
- Bubble Sort
- Insertion Sort
1. BUBBLE SORT: Bubble sort is a simple sorting algorithm. It is based on comparisons, in which each element is compared to its adjacent element and the elements are swapped if they are not in proper order.
L=eval(input(“Enter the elements:”))
for p in range(0,n-1):
for i in range(0,n-1):
L[i], L[i+1] = L[i+1],L[i]
print(“The sorted list is : “, L)
Enter the elements:[60, 24, 8, 90, 45, 87, 12, 77]
The sorted list is : [8, 12, 24, 45, 60, 77, 87, 90]
Calculating Number of Operations (Bubble sort):
2. INSERTION SORT: Sorts the elements by shifting them one by one and inserting the element at right position.
L=eval(input(“Enter the elements: “))
for j in range(1,n):
while prev>=0 and L[prev]>temp: # comparison the elements
L[prev+1]=L[prev] # shift the element forward
L[prev+1]=temp #inserting the element at proper position
print(“The sorted list is :”,L)
Enter the elements: [45, 11, 78, 2, 56, 34, 90, 19]
The sorted list is : [2, 11, 19, 34, 45, 56, 78, 90]
Calculating Number of Operations (Insertion Sort):
10.2 How insertion sort is better than bubble sort?