Re: Help me with references
- From: "Kenneth P. Turvey" <kt@xxxxxxxxxxxxxxxxxx>
- Date: Mon, 15 Aug 2005 22:10:57 +0000
Oliver Wong wrote:
> 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.
I understand this. If you know you are going to have fewer than 10 elements
why are you writing your own sorting routine? Use the API and keep the
code simple. If you aren't sure it is going to be fewer than 10 elements
you shouldn't be using bubble sort.
Then there is also the question of why you picked bubble sort from other
sorts that are O(n^2), like insertion sort, which is simpler and faster.
Again the preference should be to use the API where speed isn't a concern.
> 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.
Right, but if you know your sort will be done in no time why are you
spending time optimizing it.
--
Kenneth P. Turvey <kt@xxxxxxxxxxxxxxxxxx>
.
- Follow-Ups:
- Re: Help me with references
- From: Oliver Wong
- Re: Help me with references
- References:
- Help me with references
- From: Masamunexiii
- Re: Help me with references
- From: Kenneth P. Turvey
- Re: Help me with references
- From: Oliver Wong
- Help me with references
- Prev by Date: Re: JRE and Browser Plugin Problems
- Next by Date: Help with exiting
- Previous by thread: Re: Help me with references
- Next by thread: Re: Help me with references
- Index(es):
Relevant Pages
|