Re: New technology, old idea.... why not?
- From: Eric Sosman <Eric.Sosman@xxxxxxx>
- Date: Thu, 28 Feb 2008 15:53:59 -0500
TheBigPJ wrote:
[...]
Question
- Are we there then on sorting data? At the end? Or just very close
to it?
A lot depends on how you formulate the problem. If you
sort using pairwise comparisons and you have no exploitable
prior knowledge of the existing arrangement, then it's not
hard to show that the problem is O(N log N). These are the
assumptions usually made for "general-purpose" sorting, and
one can see why: in Java, it means you can sort anything
that implements Comparable or for which you can build a
Comparator, so the sorting methods don't need information
about the nature of the objects being sorted.
But "special-purpose" sorting is another matter! For
example, if you know that the original sequence is in order
except for possibly one pair of adjacent items, the problem
shrinks down to O(N). Or if you have a way to determine the
order of items without comparing them -- that's what your
method does, more or less -- you may be able to get to an
O(N) sort.
There's even an O(1) sort, which I've always seen explained
in terms of pasta. You've got many pieces of uncooked spaghetti,
and you want to sort them by length. So you pick 'em all up in
a bundle, hold it vertically, and slam one end down on the
counter. Lo! The tallest strand now stands higher than all
the others, and the shortest strand stands lower, and so on
for all the in-betweens. They're "sorted" in just one step,
and with zero comparisons! (Of course, the task of picking
out the strands in sorted order still lies ahead ...)
Finally, big-Oh is not the end of the tale. If I offer
you several O(N logN) sorting methods, would you be expect them
all to take the same amount of time on the same inputs? If you
do, you don't understand big-Oh!
--
Eric.Sosman@xxxxxxx
.
- References:
- New technology, old idea.... why not?
- From: TheBigPJ
- Re: New technology, old idea.... why not?
- From: Eric Sosman
- Re: New technology, old idea.... why not?
- From: TheBigPJ
- New technology, old idea.... why not?
- Prev by Date: Re: Socket with setSoTimeout() never times out
- Next by Date: Re: Can't load servlet from Tomcat from other machines
- Previous by thread: Re: New technology, old idea.... why not?
- Next by thread: Re: New technology, old idea.... why not?
- Index(es):
Relevant Pages
|
|