Re: Sorting a vector based on another datas



Daniel Pitts wrote:

If you have a large number of elements bubble sort will be very slow --
it is the worst method to sort any kind of data.

Kai

Mostly correct. There are worse sorts than bubble sort.
Permutation sort, for example. Try every permutation until you find
one that is sorted.

Or Random Sort (aka BogoSort)...

My personal favourite, though, is Non-Sort. Here's a Java implementation in
case anyone needs it:

/**
* Non-sort, the fastest known probabilistic sorting algorithm.
*
* This is a probabilistic algorithm, and so is <em>not guaranteed</em>
* to return the correct answer, but &mdash; unlike many sorting
* algorithms &mdash; it <em>is</em> guaranteed that its runtime will
* not be affected by the order of the input elements. Indeed, the runtime
* is O(1) regardless of the input. However &mdash; and again, unlike
* many sorting algorithms &mdash; the order of the input <em>does</em>
* influence the probability of the algorithm producing the correct answer,
* reaching 100% for fully sorted inputs.
*
* @param list the list to be sorted.
* @return the sorted list. Callers should not assume this
* will be != to the input list.
*/
public static <X> java.util.List<X>
nonSort(java.util.List<X> list)
{
return list;
}


I also have an in-place version (plug-compatible with
java.util.Collections.sort(List)), if required.

-- chris



.



Relevant Pages

  • Re: Sorting a vector based on another datas
    ... Permutation sort, for example. ... However and again, unlike ... influence the probability of the algorithm producing the correct answer, ...
    (comp.lang.java.programmer)
  • Re: largest no
    ... Sort the columns of each row into ascending order. ... Sorry, permutation sort isn't exponential-time. ...
    (comp.lang.c)
  • Re: largest no
    ... Sort the columns of each row into ascending order. ... Sorry, permutation sort isn't exponential-time. ...
    (comp.lang.c)