Re: How to prove that a random sort algorithm converges?



[James]
Supposed I want to sort four numbers {5, 2, 4, 3}
I randomly select a pair of two numbers at adjacient poisitions, say i
and i+1, and I swap their position if the value at position i is
greater than the value at position i+1 (e.g., 5 > 2 so swap their
positions).

If I do this (random selection and ordering) long enough, I would
expect that the numbers are sorted.

My question is: how do I prove that this algorithm converges?

[Tim Peters]
I'd try proof by induction on the number of inversions. An "inversion" is
an index pair <i, j> where i < j and x_i > x_(i+1).

Oops! My mistake: that should say

where i < j and x_i > x_j

The rest wasn't affected by that mistake, simply because the rest had the
correct definition of inversion in mind ;-) Like so:

For example, in your example there are 4 inversions: 5 > 2, 5 > 4,
5 > 3, and 4 > 3.

...


.



Relevant Pages

  • Re: Help: Randomizing a List of Numbers
    ... Huh? ... As long as you don't make the mistake of doing the swap between the ... items so as to avoid moving them a lot does not change the fact that ...
    (sci.crypt)
  • Re: Coping with the demise of b&m etiquette
    ... James, I think the attorney in you is coming out in that last question. ... a tournament situation it is ABSOLUTELY NECESSARY to stop the mistake ... or call the floorman if it's too late to stop the mistake to ...
    (rec.gambling.poker)
  • Re: JSHs mistakes happen all the time
    ... James Harris wrote: ... even without seeing this particular minor mistake. ... a mathematician so I cannot tell, but I guess real mathematicians have ...
    (sci.math)
  • Re: UUIDs on drives
    ... along with a number of other partitions. ... I just ran top and my swap ... (identified by UUID) ... My mistake. ...
    (Ubuntu)
  • Re: Could it be?
    ... I seem to recall you posted the first link yourself...my mistake... ... > James wrote: ... > Your link is broke. ...
    (microsoft.public.cert.exam.mcse)