I used same list to run quick sort and insertion sort but it
I used same list to run quick sort and insertion sort, but it seems that quick sort needs more comparison and more swaps than insertion sort, but it is faster. Why?
nsertion Sort 1. CPU time 0.005 32387 1972 2. umber of comparisons 3. Number of Swaps Qui ck Sort 1. CPU time 0.001 352412 43570 2 umber of comparisons 3. Number of Swaps Counting Sort: 1. CPU time: 2. Number of comparisons 2020005 3. umber of Swaps 0.005 Press any key to continueSolution
INSERTION SORT Vs QUICK SORT:
considering independentally, the insertion sort and the quicksort have their own prominence in dealing with the sorting of the given list of elements,
NOTE:
1. But, the point here is it would take less time for insertion sort to the list elements that are smaller in size and in this case the insertion sort acts best than the quicksort.
While coming to the list with more elements for sorting the quicksort is considered to be the best sorting algorithm.
2. For a pre-sorted list of elements irrespective of the sample size the insertion sort is the best algorithmas it just takes less comparisions and swapings. but for a random list of elements of great size the quick sort is most suitable.
Because:
1. The quicksort follows a linear partition way to sort the elements.
2. the quickort maintains a efficiency cache which passes through the neighbours from left and right comparing them with the pivot.
3. In insertion sort , the proces is all about comparing and swapping , the first element is compared and if necessary swapped and now the second element is compared withe third, if swapped again it goes for a comparision between the previous elements which inturn moves as bubble sort for every swap operation but in quick sort once the pivot is estimated all the elements are processed from left and right with respect to the comparisons with the pivot and then it gets swapped to its right position then the left elements and right elements of the pivot are partitioned and recursively the same proces is done and at last all are combined into a list
4. for insertion sort and quicksort ,the sample size or the list size effects the time taken during run time.For larger sample size lists the quicksort is more efficient as it maintains a cache and no backprocessing or backward comparisions are done but in the insertion sort for every comparing from the secong elements the elements before them should also be compared after every swap.
So,quicksort is more efficient than the insertion sort regarding large sample sizes.
