Re: "Sorting" assignment
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Wed, 06 Feb 2008 20:33:26 -0500
user923005 wrote:
CBFalconer <cbfalco...@xxxxxxxxx> wrote:
pete wrote:
... snip ...
It can do better depending on the order. Bubble sort can sort
this: {1,0,3,2,5,4,7,6,9,8} where all of the elements are out of
place, into ascending order in one pass.
6) Bubble sort is a stable sort.
It is also O(n * n). However mergesort is also stable, and is
always O(n Log n). Bubble sort is to all practical purposes the
worst possible general sort.
That is true for a general sort. However, it is useful in rare
{special purpose} cases (e.g. when you know the data will almost
always be almost sorted).
This arises (for instance) in chess programming. There is a list
of moves that will be nearly correctly ordered because of
previous searches. For these searches, the lists will typically
be small (about 35 items on average) and at most one or two items
will be out of place. For this type of thing, bubble sort is
actually the fastest solution.
Even here I have my doubts. That list is obviously of varying
length, and thus is most easily organized as a list [1]. Lists are
easily handled by mergesort. No need to keep track of the count of
item, reorganize into an array, etc. etc. etc.
[1] Different meaning for this 'list'.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
--
Posted via a free Usenet account from http://www.teranews.com
.
- References:
- "Sorting" assignment
- From: Ivica
- Re: "Sorting" assignment
- From: spinoza1111
- Re: "Sorting" assignment
- From: Stephen Howe
- Re: "Sorting" assignment
- From: pete
- Re: "Sorting" assignment
- From: CBFalconer
- Re: "Sorting" assignment
- From: user923005
- "Sorting" assignment
- Prev by Date: Re: "Sorting" assignment
- Next by Date: Re: Application of Various Programming Languages?
- Previous by thread: Re: "Sorting" assignment
- Next by thread: Re: "Sorting" assignment
- Index(es):
Relevant Pages
|