Newsgroups: comp.lang.c++,comp.sys.mac.programmer.help,comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!news.acsu.buffalo.edu!news.uoregon.edu!ddsw1!news.mcs.net!www.nntp.primenet.com!nntp.primenet.com!feed1.news.erols.com!phase2.worldnet.att.net!uunet!in2.uu.net!uucp1.uu.net!allegra!akalice!ark
From: ark@research.att.com (Andrew Koenig)
Subject: Re: Mergesort: why's it efficient?
Message-ID: <E1uDzs.2AI@research.att.com>
Organization: AT&T Research, Murray Hill NJ
References: <57j5dh$sh3$1@goanna.cs.rmit.edu.au> <E1ouwy.1JC@research.att.com> <6M5-4oabJaB@09.viking.ruhr.com>
Date: Tue, 3 Dec 1996 14:38:15 GMT
Lines: 39
Xref: glinda.oz.cs.cmu.edu comp.lang.c++:231066 comp.sys.mac.programmer.help:44485 comp.lang.lisp:24010

In article <6M5-4oabJaB@09.viking.ruhr.com> roc@viking.ruhr.com (Rolf Czedzak) writes:

> Your argument pushes _any_ 'realistic problem' into class O(1).

Not at all.   Admittedly the argument is entirely subjective, but
in practice, computers have the property that if you ask them to store
N objects, N will be subjectively large but log N will not be.

Suppose, for example, that we limit N to 2^100 (which is much larger
than the memory of any computer available today) and talk about
log base 2 (to make the constrasts as extreme as we can).  Then

	O(N) will be much bigger than O(1)
	O(N log N) will not be much bigger than O(N)
		[well, it might be 100 times as large, but that's
		 much, much less than 2^100]
	O(N^2) will be much bigger than O(N log N)
	O(N^3) will be much bigger than O(N^2)

and so on.  Of course there might be constant factors involved, but
they're almost surely unimportant compared to the size of N.

To make things more concrete, consider N=1,000,000, and look at four
programs with different performance characteristics:

	A program that runs in 1 microsecond takes 1 microsecond :-)
	A program that runs in N microseconds takes 1 second
	A program that runs in N log N microseconds takes about 20 seconds
	A program that runs in N^2 microseconds takes 11.6 days.

So what I am claiming is that, for practical purposes, a program that
runs in 1 second is nearly equivalent to one that runs in 20 seconds, when you
are comparing them with programs that run in 1 microsecond or in 11.6 days.

Again: O(N log N) is almost as good as O(N).  It is not almost as good
as O(1), and is much better than O(N^2).
-- 
				--Andrew Koenig
				  ark@research.att.com
