Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!news.sprintlink.net!siemens!princeton!news.princeton.edu!blume
From: blume@dynamic.cs.princeton.edu (Matthias Blume)
Subject: Re: O(1) access time vectors
In-Reply-To: Alan@lcs.mit.EDU's message of 10 Nov 1994 01:47:41 -0500
Message-ID: <BLUME.94Nov10095843@dynamic.cs.princeton.edu>
Originator: news@hedgehog.Princeton.EDU
Sender: news@Princeton.EDU (USENET News System)
Nntp-Posting-Host: dynamic.cs.princeton.edu
Organization: Princeton University
References: <39pa2j$3lv@larry.rice.edu> <9Nov1994.235932.Alan@LCS.MIT.EDU>
Date: Thu, 10 Nov 1994 14:58:43 GMT
Lines: 37


Somehow I feel that this whole discussion is pretty pointless.  Why am
I saying this? -- Because both sides are right - well - sort of.

I agree with Alan Bawden on the issue of using the ``standard''
representation for vectors (pointer to beginning of consecutive memory
cells, address arithmetic to do indexing), because on today's machines
this is by far the fastest.

However, when talking O(X) time complexity then we should not forget
that this representation always ultimately limits the maximum size of
representable vectors to the total amount of (virtual) memory
available to the application.  This is a finite constant for any given
computer installation today.

The ``balanced binary tree'' representation of vectors incurs O(log n) 
access and update times, where n is the total size of the vector.  So
if the maximum vector size if limited to a constant c (like above) then
n is limited by this constant c and the access and update times are
limited by log c, which is also constant.

Moreover, if we'd manage to get around the size limitation for the
``standard'' respresentation -- this is to say that we can have
arbitrary size vectors -- then we can no longer reasonably assume
constant access times in this case either.  The reason for this is
that the access (and update) operators must look at all the bits in
the index -- but now this number of bits is not bounded by a constant
anymore.  In fact, it can only be bounded by O(log n), with n being
the size of the vector.

Ultimately we arrive at the same asymptotic bounds for *both*
representations.  The only argument that can (and must!) be made in
favor of the standard respresentation is that the hidden constant in
``big O'' is typically *much* smaller.

--
-Matthias
