Sujet : Re: Baby X is bor nagain
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.cDate : 21. Jun 2024, 10:19:10
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v53gie$33k73$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 20/06/2024 18:56, Malcolm McLean wrote:
Yes, a qsort written in the natural way can getstuck if a sub0array it considered sorted becmes not sortted on the next pass.
I have no idea what you might think of as the "natural" way to implement qsort. But if it were, as the name implies, a quicksort, then it would not get stuck. At each step, progress is always made - even with a comparison function that gave random values, you'd still have a worst case complexity of O(n²).
The only sorting algorithm I can think of that might get stuck with a slightly broken comparison function would be a poor bubblesort implementation that is run over the whole array every round, simply repeating until no changes are made in a round.