Re: Problem about the used time to sort an array
- From: Eric Sosman <esosman@xxxxxxxxxxxxxxxxxxx>
- Date: Tue, 27 Jun 2006 08:17:04 -0400
prado wrote:
Sorry,
I have to sort an string array. I am using the bubble method to do
this. I don't know why there is this diferent of time in 2 computers.
[...]
Bubble sort is a poor algorithm. First, it has O(N*N)
average complexity, which means that the time to sort is
roughly proportional to the square of the number of items
being sorted: sorting fifty items takes ~25 times as long as
sorting ten. Second, even when compared to other O(N*N)
sorting algorithms, bubble sort is usually slower: all the
running times are roughly proportional to the square of N
but with different proportionality factors, and bubble sort's
is larger than most others.
You mention that the array has ~7000 elements, and this
is far too many for an O(N*N) sort -- it will take about as
much time to sort this array as to sort half a million ten-
element arrays. Java provides implementations of better
sorting methods in the Arrays and Collections classes; use
them, that's why they're there.
--
Eric Sosman
esosman@xxxxxxxxxxxxxxxxxxx
.
- References:
- Problem about the used time to sort an array
- From: prado
- Re: Problem about the used time to sort an array
- From: Robert Klemme
- Re: Problem about the used time to sort an array
- From: prado
- Problem about the used time to sort an array
- Prev by Date: Screen Refresh
- Next by Date: Re: Networking of JVMs
- Previous by thread: Re: Problem about the used time to sort an array
- Next by thread: Re: Problem about the used time to sort an array
- Index(es):
Relevant Pages
|