Does quicksort use more comparisons than mergesort? If so, then why is it a faster sorting algorithm?
-
-
Answer:
http://en.wikipedia.org/wiki/Merge_sort In the worst case, merge sort does about 39% fewer comparisons than quicksort does in the average case; merge sort always makes fewer comparisons than quicksort.. merge sort is stable than quick sort. -> why it is faster? you keep dividing the numbers into sub divisions until you reach 1 element in each sub divisions. if you check the diagram in wiki (http://upload.wikimedia.org/wikipedia/commons/thumb/e/e6/Merge_sort_algorithm_diagram.svg/300px-Merge_sort_algorithm_diagram.svg.png), you only sort within each divisions and then merge them. in regular sorting you would begin from the first number and compare it with every other elements.. example: 3 2 7 1 REGULAR SORT(how humans would do!!) ->you start from 3, compare it with 2, swap them (2 3 7 1). -> compare 3 with 7 and just keep them as it is (2 3 7 1) -> compare 3 with 1 and swap them (2 1 7 3) -> this process goes on and on MERGE SORT: divide them to divisions. -> [3 2] [7 1] -> [[ 3] [2]] [[7] [1]] -> now start from left in each divisions, swap them if needed with in each divisions and merge them. [2 3] [1 7] -> again start from left. compare 2 and 1 (first elements with each divisions) [1 2 ], sort them and move them to bigger box. next compare 3 and 7. move them to bigger fox [1 2 3 7]. [1 2 3 7] it can be more clear if you look the animation. you ll realize merge sort is faster than regular sorting. -> if you analyze quick sort, it looks wacky and merge sort looks more stable!
Vitteorca54 at Yahoo! Answers Visit the source
Other answers
http://en.wikipedia.org/wiki/Merge_sort In the worst case, merge sort does about 39% fewer comparisons than quicksort does in the average case; merge sort always makes fewer comparisons than quicksort.. merge sort is stable than quick sort. -> why it is faster? you keep dividing the numbers into sub divisions until you reach 1 element in each sub divisions. if you check the diagram in wiki (http://upload.wikimedia.org/wikipedia/commons/thumb/e/e6/Merge_sort_algorithm_diagram.svg/300px-Merge_sort_algorithm_diagram.svg.png), you only sort within each divisions and then merge them. in regular sorting you would begin from the first number and compare it with every other elements.. example: 3 2 7 1 REGULAR SORT(how humans would do!!) ->you start from 3, compare it with 2, swap them (2 3 7 1). -> compare 3 with 7 and just keep them as it is (2 3 7 1) -> compare 3 with 1 and swap them (2 1 7 3) -> this process goes on and on MERGE SORT: divide them to divisions. -> [3 2] [7 1] -> [[ 3] [2]] [[7] [1]] -> now start from left in each divisions, swap them if needed with in each divisions and merge them. [2 3] [1 7] -> again start from left. compare 2 and 1 (first elements with each divisions) [1 2 ], sort them and move them to bigger box. next compare 3 and 7. move them to bigger fox [1 2 3 7]. [1 2 3 7] it can be more clear if you look the animation. you ll realize merge sort is faster than regular sorting. -> if you analyze quick sort, it looks wacky and merge sort looks more stable!
deepak
Both algorithm complexity of order same O(NlogN) where N is number of elements. Both recursive also. Both involves movements of elements. quicksorting has both best and worst case behaviors. For large value of N, quicksorting does use less number of computations.
James Bond
Both algorithm complexity of order same O(NlogN) where N is number of elements. Both recursive also. Both involves movements of elements. quicksorting has both best and worst case behaviors. For large value of N, quicksorting does use less number of computations.
James Bond
Related Q & A:
- Why doesn't a computer recognise a printer?Best solution by Yahoo! Answers
- Can somebody suggest an easy to use DVD recorder for the purpose of recording from camcorder onto a DVD?Best solution by imshopping.com
- How do you get a faster metabolism?Best solution by ChaCha
- How to become a faster long distance runner?Best solution by eHow old
- How do I become a faster sprinter?Best solution by ChaCha
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.