What are the different types of sorting? Explain the difference between them?
Answers
Answered by
0
What are all the differences between insertion sort, selection sort, and bubble sort?
Still have a question? Ask your own!
What is your question?
6 ANSWERS

Henna Peterson, Software Developer
Answered Oct 6, 2017
Bubble Sort - It is a sorting algorithm in which two adjacent elements of an array are checked and swapped if they are in wrong order and this process is repeated until we get a sorted array.
In this first two elements of the array are checked and swapped if they are in wrong order. Then first and third elements are checked and swapped if they are in wrong order. This continues till the lat element is checked and swapped if necessary.
Selection Sort - It is also a sorting algorithm in which first step is to find the smallest element in the array. This smallest element is swapped with the first element. After this, search for the smallest element in the subarray formed by excluding the first element and compare it with the first element of the subarray. Repeat it till the array gets sorted.
Insertion Sort - In this, the second element is compared with the first element and is swapped if it is not in order. Similarly, we take the third element in the next iteration and place it at the right place in the subarray of the first and second elements (as the subarray containing the first and second elements is already sorted). We repeat this step with the fourth element of the array in the next iteration and place it at the right position in the subarray containing the first, second and the third elements. We repeat this process until our array gets sorted.
Still have a question? Ask your own!
What is your question?
6 ANSWERS

Henna Peterson, Software Developer
Answered Oct 6, 2017
Bubble Sort - It is a sorting algorithm in which two adjacent elements of an array are checked and swapped if they are in wrong order and this process is repeated until we get a sorted array.
In this first two elements of the array are checked and swapped if they are in wrong order. Then first and third elements are checked and swapped if they are in wrong order. This continues till the lat element is checked and swapped if necessary.
Selection Sort - It is also a sorting algorithm in which first step is to find the smallest element in the array. This smallest element is swapped with the first element. After this, search for the smallest element in the subarray formed by excluding the first element and compare it with the first element of the subarray. Repeat it till the array gets sorted.
Insertion Sort - In this, the second element is compared with the first element and is swapped if it is not in order. Similarly, we take the third element in the next iteration and place it at the right place in the subarray of the first and second elements (as the subarray containing the first and second elements is already sorted). We repeat this step with the fourth element of the array in the next iteration and place it at the right position in the subarray containing the first, second and the third elements. We repeat this process until our array gets sorted.
Answered by
5
We looked at 6 different algorithms - Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, Heap Sort, Quick Sort - and their implementations in Python. The amount of comparison and swaps the algorithm performs along with the environment the code runs are key determinants of performance.
Similar questions