Re: how can i large divide?
- From: Ben Bacarisse <ben.usenet@xxxxxxxxx>
- Date: Sat, 07 Jun 2008 01:36:20 +0100
Richard Heathfield <rjh@xxxxxxxxxxxxxxx> writes:
Bartc said:
<snip>
And I'm guessing my code was O(log2 n) because it worked in binary. Would
this make it faster or slower than O(log n) or is there no difference?
Big-O notation is a representation of computational complexity, not
runtime. The two are related, but not identical.
Let's say we have an O(6*n) algorithm. You can easily turn this into an
O(n) algorithm by buying a computer that works six times quicker than the
old one. You can even go to your vendor and say "we currently have a Model
X, but now we need something 6 times quicker than a Model X". He gives you
a Model Y, you give him much money, and suddenly you have O(n). So the
only real difference between O(6*n) and O(n) is a bit of cash,
right?
My main point is below but, for the record, O(6*n) = O(n) using = in
its strict mathematical sense. I think it is slightly misleading to
suggest any difference between them (i.e. "the only real difference"
is none at all).
But if we have an O(n*n) algorithm, we hit a problem.
and we also hit a terminology problem. Most people use O(...) when
they really want to say Theta(...). Merge sort is "an O(n*n)
algorithm" in a very precise sense. The number of comparisons
performed by a merge sort is a function MS(n) which is in O(n*n) just
as the number of comparisons done by bubble sort, BS(n), is in O(n*n).
Of course, MS(n) is also in O(n*log(n)) which BS(n) is not.
We should all get in the habit of saying "a Theta(n*n) algorithm" (if
it is true). Saying that something is O(n*n) is just a way of saying
that it's metric (time, space, no of comparisons, whatever) is no
"worse" than any other O(n*n) function, but it may be whole lot
better and big-O can't tell us that.
<for anyone who still cares>
O(n*n) is a set of functions, nothing more nothing less. Every
function, f, in O(n*n) has the property that one can find a C > 0 and
an x0 such that for all x > x0, abs(f(x)) < C*x*x.
Saying that a function f is in Theta(n*n) means that, eventually, its
absolute value is bounded both above and below by a positive multiple
of n*n. I.e. that we can find C1 and C2 > 0 and an x0 such that for
all x > x0, C1*x*x < abs(f(x)) < C2*x*x.
--
Ben.
.
- Follow-Ups:
- Re: how can i large divide?
- From: Johannes Bauer
- Re: how can i large divide?
- From: Richard Heathfield
- Re: how can i large divide?
- References:
- how can i large divide?
- From: jty0734
- Re: how can i large divide?
- From: Malcolm McLean
- Re: how can i large divide?
- From: Richard Heathfield
- Re: how can i large divide?
- From: Bartc
- Re: how can i large divide?
- From: Owen Jacobson
- Re: how can i large divide?
- From: Bartc
- Re: how can i large divide?
- From: Richard Heathfield
- Re: how can i large divide?
- From: Bartc
- Re: how can i large divide?
- From: Richard Heathfield
- how can i large divide?
- Prev by Date: Re: sqrt() double trouble
- Next by Date: Re: Accessing flags
- Previous by thread: Re: how can i large divide?
- Next by thread: Re: how can i large divide?
- Index(es):
Relevant Pages
|