What is Sorting in Python ?
Sorting means to arrange elements in increasing or decreasing order. Sorting algorithm tells us that how we are going to arrange elements in increasing or decreasing order.
Output of sorting algorithm depends on the type of comparison operator used to arrange elements.
The sorting algorithm takes the elements(numbers or alphabets) and arrange them in particular order (increasing or decreasing)
for example : The sorting algorithms takes following numbers as input and arranged in increasing order
INPUT : 23, 12, 35, 40, 56, 20, 1
OUTPUT : 1, 12, 20, 23, 35, 40, 56
The sorting algorithms takes following numbers as input and arranged in decreasing order.
INPUT : 99, 88, 121, 10, 5, 112, 15, 1, 23
OUTPUT: 121, 112, 99, 88, 23, 15, 10, 5, 1
The sorting algorithms takes following alphabets as input and arranged in decreasing order of ASCII Value.
INPUT : A, b, C, E, d, F, D
OUTPUT : d, b, F, E, D, C, A
Why Sorting is required?
Elements can be searched easily if data is arranged in increasing or decreasing order. Sorting arranged the data in more readable format.
Sorting in daily life
We come across many things in our daily life which are arranged in increasing or decreasing order. for example
- Words are arranged in alphabetical order in Dictionary
- Pages in books are arranged in increasing order.
- Phone numbers in telephone directory are arranged in alphabetical order.
Types of Sorting algorithm
There are many sorting algorithm which can be used to arrange elements in increasing or decreasing order.
- Bubble Sort
- Insertion Sort
- Quick Sort
- Merge Sort
- Selection Sort etc.
Exercise :
Q1. What do you mean by Sorting in Python?
Q2. Name two Sorting algorithm.
Q3. Write the output of following list after applying bubble sort algorithm for arranging in increasing order.
L = [34, 56, 12, 3, 40, 78, 67]
Q4. Why Sorting is required?
Q5. Arrange the following list in increasing order.
L = [“A”, ‘b’, ‘D’, ‘g’ , ‘Z’ , ‘i’]
Click for detail : Bubble Sort
Click for Important Questions of Bubble Sort
Click for detail : Insertion Sort
Class 12 Computer Science Sample Paper 2020-2021.
Class 12 Computer Science Sample Paper Marking Scheme
Class 12 Computer Science Test Series