Re: Problem about the used time to sort an array



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
.



Relevant Pages

  • Re: Sorting routine
    ... n RSHIFT shifts n bits. ... in the output array. ... This would be handy for sign sorting of 2's complement. ... So Radix/Distribution sort is about 1.4 times faster than Sedge's Sort. ...
    (comp.lang.forth)
  • Re: Efficiently Extracting Identical Values From A List/Array
    ... struct SortHelper ... Now sort that array according to NodeIndex: ... running through the data structure and sorting things out. ...
    (comp.lang.cpp)
  • Re: indirect sort
    ... I wrote a Comparator (I don't want to use ... Comparable in order to be able to choose the field I am sorting by) ... a way to create a doublearray of my fields I want to sort by, ...
    (comp.lang.java.programmer)
  • Re: "Sorting" assignment
    ... And many others prefer to call partition exchange because "quicksort" ... bin B depending on whether it is greater than, ... If the array is already sorted, this means that you end up ... attempt to sort them. ...
    (comp.programming)
  • Re: A Fast sorting algorithm for almost sorted data
    ... far my compressor has potential but is nowhere near ready. ... It does however make heavy use of sorting. ... which I am currently calling Run sort. ... entire selected run can be added to the sorted output array. ...
    (comp.compression)