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
- Selection sort algorithm is 60% more efficient than bubble sort algorithm.
- Selection sort algorithm is easy to implement.
- Selection sort algorithm can be used for small data sets, unfortunately Insertion sort algorithm best suitable for it.
Disadvantages of selection sort
- Insertion sort algorithm is far better than selection sort algorithm.
- 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
- Bubble sort is one of the easiest sort algorithum
- It is easy to implement
- Elements are swapped in place, no use of extra array
Disadvantages of Bubble Sort
- Bubble sort algorithum is not suitable for large data sets
- 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
- Simple to code
- Good performance with small list
- Memory efficient
Disadvantages of Insertion sort
- Poor efficiency when dealing with huge list of items
- Requires extra space
- Not as quick as merge or quick sort