Re: Help me with references
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Mon, 15 Aug 2005 19:45:44 GMT
"Kenneth P. Turvey" <kt@xxxxxxxxxxxxxxxxxx> wrote in message
news:erp6t2-etl.ln1@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> If this is just a learning exercise then that's great, but if you really
> want to sort something there really isn't ever a good use for bubble sort.
> You should probably let Java do the sorting for you unless you have a
> reason to use a specific algorithm. That algorithm will never be bubble
> sort.
Bubblesort is O(n^2) and Mergesort is O(n log(n)), but the O(n^2) in
BubbleSort has a small constant. A clever sorting algorithm might use
Mergesort of Quicksort if the size of the set is greater than 10 elements,
but use BubbleSort if it's smaller than 10 elements, for example.
Consider sorting a set of size 40 for example. When you call quicksort,
it might break it into 2 sets of size 20 each. Call quicksort on each of
these, and you have 4 sets of size 10 each. It's actually faster to
bubblesort these sets of size 10 than to do further quicksorting. Once you
have 10 sorted sets, you can merge them back together using the normal
quicksort algorithm again.
- Oliver
.
- Follow-Ups:
- Re: Help me with references
- From: Kenneth P. Turvey
- Re: Help me with references
- From: Eric Sosman
- Re: Help me with references
- References:
- Help me with references
- From: Masamunexiii
- Re: Help me with references
- From: Kenneth P. Turvey
- Help me with references
- Prev by Date: Re: anyone know what this means?
- Next by Date: Re: JRE and Browser Plugin Problems
- Previous by thread: Re: Help me with references
- Next by thread: Re: Help me with references
- Index(es):
Relevant Pages
|