Re: Help me with references
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Tue, 16 Aug 2005 13:19:58 GMT
"Kenneth P. Turvey" <kt@xxxxxxxxxxxxxxxxxx> wrote in message
news:hgg7t2-ur4.ln1@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> 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.
I'm not trying to tell the OP that implementing bubble sort is a good
idea. All I was doing was pointing out that your statement "That algorithm
will never be bubble sort." is not nescessarily true in all situations.
If you're interested though, I can still answer the questions in your
post.
- Oliver
.
- Follow-Ups:
- Re: Help me with references
- From: Kenneth P. Turvey
- 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
- Re: Help me with references
- From: Kenneth P. Turvey
- Help me with references
- Prev by Date: Re: Im getting frustrated and angry!
- Next by Date: Re: Help me with references
- Previous by thread: Re: Help me with references
- Next by thread: Re: Help me with references
- Index(es):
Relevant Pages
|