Searching and Sorting Techniques Notes

Sorting

Sorting means to arrange the data either in ascending order or descending order. It is the process of rearranging a sequence of objects so as to put them in some logical order.

 

 

Selection Sort :  Find the minimum element in unsorted array and swap it with the element in the begining  of the sorted array.

 

 

Advantages of selection sort

  1. Selection sort algorithm is 60% more efficient than bubble sort algorithm.
  2. Selection sort algorithm is easy to implement.
  3. Selection sort algorithm can be used for small data sets, unfortunately Insertion sort algorithm best suitable for it.

Disadvantages of selection sort

  1. Insertion sort algorithm is far better than selection sort algorithm.
  2. Runtime of selection sort is algorithum is very poor

Bubble Sort : Bubble sort is a simple sorting algorithum. This sorting algorithum is compaison based algorithum is which each pair of adjacmt elements is compared and element are swapped if they  are not in order.

  • Compare two adjoining values and exchange them, if they are not in proper order.
  • After pass1, the largest element of the list will be at bottom.
  • If we have array of n elements ,we have to do n-1 iterations before we get our sorted array

Advantages of Bubble sort   

  1. Bubble sort is one of the easiest sort algorithum
  2. It is easy to implement
  3. Elements are swapped in place, no use of extra array

Disadvantages of Bubble Sort

  1. Bubble sort algorithum is not suitable for large data sets
  2. The code become complex for larger number of data

 

 

Insertion  Sort :  

Insert an element from unsorted array to its correct position in sorted array . In Insertion sort, we assume the first element to be sorted.

 

Advantages of Insertion sort

  1. Simple to code
  2. Good performance with small list
  3. Memory efficient

Disadvantages of Insertion sort

  1. Poor efficiency when dealing with huge list of items
  2. Requires extra space
  3. Not as quick as merge or quick sort

 

Copywrite © 2020-2024, CBSE Python,
All Rights Reserved