Sorting Class 11 Computer Science Notes And Questions

Notes Class 11

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

10.1 DEFINITION:
To arrange the elements in ascending or descending order.
In this chapter we shall discuss two sorting techniques:

  1. Bubble Sort
  2. 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.

Sorting Class 11 Computer Science Notes And Questions

PROGRAM:
L=eval(input(“Enter the elements:”))
n=len(L)
for p in range(0,n-1):
for i in range(0,n-1):
if L[i]>L[i+1]:
L[i], L[i+1] = L[i+1],L[i]
print(“The sorted list is : “, L)

OUTPUT:
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):

Sorting Class 11 Computer Science Notes And Questions

2. INSERTION SORT: Sorts the elements by shifting them one by one and inserting the element at right position.

Sorting Class 11 Computer Science Notes And Questions

PROGRAM:
L=eval(input(“Enter the elements: “))
n=len(L)
for j in range(1,n):
temp=L[j]
prev=j-1
while prev>=0 and L[prev]>temp: # comparison the elements
L[prev+1]=L[prev] # shift the element forward
prev=prev-1
L[prev+1]=temp #inserting the element at proper position
print(“The sorted list is :”,L)

OUTPUT:
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):

Sorting Class 11 Computer Science Notes And Questions

10.2 How insertion sort is better than bubble sort?

Sorting Class 11 Computer Science Notes And Questions
Sorting Class 11 Computer Science Notes And Questions