|
|
Subject:
Computer Algorithm Question
Category: Computers > Algorithms Asked by: nat54321-ga List Price: $6.00 |
Posted:
15 Sep 2004 14:35 PDT
Expires: 15 Oct 2004 14:35 PDT Question ID: 401709 |
When would you use mergesort over quicksort and vise-versa? |
|
There is no answer at this time. |
|
Subject:
Re: Computer Algorithm Question
From: frde-ga on 17 Sep 2004 06:33 PDT |
QuickSort abuses the stack as it is a recursive algorithm (sure one can write a non recursive version using the heap instead) Typically for each recursion it uses [Ret Addr] [pItem1] [pItem2] ie: 16 bytes The problem is that it eats memory, so it is inevitably finite in its capacity. MergeSort is dividing the data down into buffers and then merging them. It is simply repeatedly subdividing the data and merging it. Also not an 'inplace' sort. One needs a recipient buffer the same size as the original data for the 'merge' (or with tweaking, half the size - further tweaking reduces it but ...) I have long preferred the Shell Sort algorithm, which is totally 'inplace' (Also sometimes called the Comb Sort) The academic anser is going to be : use MergeSort when the remaining stack divided by 16 is less than the number of keys. The real world answer is sort stuff on disk in blocks and recursively merge them if it is anything above a trivial amount of data (eg: a few hundred Kb) and use ShellSort for the block sorting. Speed matters, but an out of stack space or heap space gives a zero speed. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |