Google Answers Logo
View Question
 
Q: Computer Algorithm Question ( No Answer,   1 Comment )
Question  
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?
Answer  
There is no answer at this time.

Comments  
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.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

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 Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy