Re: Isn't that beauty ? (no it's not)

Liste des GroupesRevenir à cl c 
Sujet : Re: Isn't that beauty ? (no it's not)
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.c
Date : 19. Mar 2026, 15:49:16
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <10ph2db$pn58$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 24 25
User-Agent : Mozilla Thunderbird
On 19/03/2026 09:19, Michael S wrote:
On Wed, 18 Mar 2026 11:20:03 +0100
David Brown <david.brown@hesbynett.no> wrote:

The problem with bubble sort is that relatively to other popular
O(n**2) sorting algorithms, i.e. using Knuth's nomenclature,
Straight Insertion and Straight Selection, it is not just
measurably slower, but also a little more complicated to code.
>
I am not convinced on the complexity point - but it will vary by
programming language, and what you consider "complicated".
>
 The language is 'C'.
Here are implementations of Straight Insertion and Straight Select.
Show me implementation of Bubble sort that is not at least a little
more complicated.
Remember that it has to be "real" bubble sort, not a simplified bubble
sort that does unnecessary work by starting each time from the
beginning. Your variant shall avoid obviously unnecessary work and
shall be opportunistic, i.e. quick at handling almost sorted cases.
 #include <stddef.h>
#include <string.h>
 void straight_insertion_sort(const char** buffer, size_t n)
{
   for (size_t i = 1; i < n; ++i) {
     const char* a = buffer[i];
     size_t k;
     for (k = i; k != 0; --k) {
       if (!(strcmp(a, buffer[k-1]) < 0))
         break;
       buffer[k] = buffer[k-1];
     }
     buffer[k] = a;
   }
}
 void straight_select_sort(const char** buffer, size_t n)
{
   for (size_t i = 1; i < n; ++i) {
I think this needs to start from 0.

     const char* mn = buffer[i];
     size_t mn_k = i;
     for (size_t k = i+1; k < n; ++k) {
       if (strcmp(buffer[k], mn) < 0) {
         mn = buffer[k];
         mn_k = k;
       }
     }
     buffer[mn_k] = buffer[i];
     buffer[i] = mn;
   }
}
I ported both of these to scripting code, then compared against the simplest version of bubble-sort.
They were faster, by 2.7x and 3.6x respectively. But both still had O(n-squared) behaviour.
Now that I have copies, I may possible use them next time I might have written a bubble-sort. But I would only have done that anyway when I knew its performance was tolerable or negligible.
Normally however (and again in scripting code) I'd use my built-in sort() based on quicksort, which is nearly 1000 times faster than bubble-sort for my test (sort 20K random strings), and some 300x faster than your routines. It's not O(n-squared) either.
So basically, if I don't care about speed or its not needed, I might as well use bubble-sort.

Date Sujet#  Auteur
12 Mar 26 * Isn't that beauty ?185Bonita Montero
12 Mar 26 +- Re: Isn't that beauty ?1Bonita Montero
12 Mar 26 +* Re: Isn't that beauty ?3Janis Papanagnou
12 Mar 26 i`* Re: Isn't that beauty ?2Bonita Montero
12 Mar 26 i `- Re: Isn't that beauty ?1Janis Papanagnou
12 Mar 26 `* Re: Isn't that beauty ? (no it's not)180DFS
12 Mar 26  +* Re: Isn't that beauty ? (no it's not)3Bonita Montero
12 Mar 26  i`* Re: Isn't that beauty ? (no it's not)2tTh
12 Mar 26  i `- Re: Isn't that beauty ? (no it's not)1Bonita Montero
12 Mar 26  +* Re: Isn't that beauty ? (no it's not)170Bonita Montero
12 Mar 26  i`* Re: Isn't that beauty ? (no it's not)169DFS
12 Mar 26  i `* Re: Isn't that beauty ? (no it's not)168Bonita Montero
12 Mar 26  i  +* Re: Isn't that beauty ? (no it's not)16DFS
12 Mar 26  i  i+* Re: Isn't that beauty ? (no it's not)2Bonita Montero
12 Mar 26  i  ii`- Re: Isn't that beauty ? (no it's not)1Bonita Montero
12 Mar 26  i  i`* Re: Isn't that beauty ? (no it's not)13Bonita Montero
12 Mar 26  i  i +* Re: Isn't that beauty ? (no it's not)8Janis Papanagnou
13 Mar 26  i  i i`* Re: Isn't that beauty ? (no it's not)7Bonita Montero
13 Mar 26  i  i i `* Re: Isn't that beauty ? (no it's not)6Janis Papanagnou
13 Mar 26  i  i i  `* Re: Isn't that beauty ? (no it's not)5Bonita Montero
13 Mar 26  i  i i   `* Re: Isn't that beauty ? (no it's not)4Chris M. Thomasson
13 Mar 26  i  i i    `* Re: Isn't that beauty ? (no it's not)3Bonita Montero
13 Mar 26  i  i i     +- [OT] AI - questions and answers (was Re: Isn't that beauty ? (no it's not))1Janis Papanagnou
13 Mar 26  i  i i     `- Re: Isn't that beauty ? (no it's not)1Chris M. Thomasson
13 Mar 26  i  i `* Re: Isn't that beauty ? (no it's not)4DFS
13 Mar 26  i  i  +- Re: Isn't that beauty ? (no it's not)1Bonita Montero
14 Mar 26  i  i  `* Re: Isn't that beauty ? (no it's not)2Bonita Montero
14 Mar 26  i  i   `- Re: Isn't that beauty ? (no it's not)1DFS
12 Mar 26  i  +- Re: Isn't that beauty ? (no it's not)1Bonita Montero
12 Mar 26  i  +* Re: Isn't that beauty ? (no it's not)143DFS
13 Mar 26  i  i+- Re: Isn't that beauty ? (no it's not)1Bonita Montero
13 Mar 26  i  i+* Re: Isn't that beauty ? (no it's not)120Bonita Montero
13 Mar 26  i  ii`* Re: Isn't that beauty ? (no it's not)119DFS
14 Mar 26  i  ii `* Re: Isn't that beauty ? (no it's not)118Bonita Montero
14 Mar 26  i  ii  `* Re: Isn't that beauty ? (no it's not)117DFS
14 Mar 26  i  ii   +* Re: Isn't that beauty ? (no it's not)2Bonita Montero
14 Mar 26  i  ii   i`- Re: Isn't that beauty ? (no it's not)1DFS
14 Mar 26  i  ii   `* Re: Isn't that beauty ? (no it's not)114Bonita Montero
14 Mar 26  i  ii    `* Re: Isn't that beauty ? (no it's not)113Bonita Montero
14 Mar 26  i  ii     +* Re: Isn't that beauty ? (no it's not)5DFS
14 Mar 26  i  ii     i`* Re: Isn't that beauty ? (no it's not)4Bonita Montero
14 Mar 26  i  ii     i `* Re: Isn't that beauty ? (no it's not)3DFS
14 Mar 26  i  ii     i  +- Re: Isn't that beauty ? (no it's not)1Bonita Montero
14 Mar 26  i  ii     i  `- Re: Isn't that beauty ? (no it's not)1Bonita Montero
14 Mar 26  i  ii     +* Re: Isn't that beauty ? (no it's not)103Bart
14 Mar 26  i  ii     i+- Re: Isn't that beauty ? (no it's not)1Bonita Montero
16 Mar 26  i  ii     i`* Re: Isn't that beauty ? (no it's not)101DFS
16 Mar 26  i  ii     i +* Re: Isn't that beauty ? (no it's not)13Richard Harnden
16 Mar 26  i  ii     i i+- Re: Isn't that beauty ? (no it's not)1Bart
17 Mar 26  i  ii     i i`* Re: Isn't that beauty ? (no it's not)11DFS
17 Mar 26  i  ii     i i `* Re: Isn't that beauty ? (no it's not)10Richard Harnden
17 Mar 26  i  ii     i i  `* Re: Isn't that beauty ? (no it's not)9DFS
17 Mar 26  i  ii     i i   `* Re: Isn't that beauty ? (no it's not)8Richard Harnden
17 Mar 26  i  ii     i i    +* Re: Isn't that beauty ? (no it's not)6Richard Harnden
17 Mar 26  i  ii     i i    i`* Re: Isn't that beauty ? (no it's not)5DFS
17 Mar 26  i  ii     i i    i +* Re: Isn't that beauty ? (no it's not)3Richard Harnden
17 Mar 26  i  ii     i i    i i`* Re: Isn't that beauty ? (no it's not)2Janis Papanagnou
17 Mar 26  i  ii     i i    i i `- Re: Isn't that beauty ? (no it's not)1Richard Harnden
17 Mar 26  i  ii     i i    i `- Re: Isn't that beauty ? (no it's not)1Bart
17 Mar 26  i  ii     i i    `- Re: Isn't that beauty ? (no it's not)1DFS
16 Mar 26  i  ii     i +* Re: Isn't that beauty ? (no it's not)73Bart
17 Mar 26  i  ii     i i`* Re: Isn't that beauty ? (no it's not)72DFS
17 Mar 26  i  ii     i i `* Re: Isn't that beauty ? (no it's not)71Bart
17 Mar 26  i  ii     i i  `* Re: Isn't that beauty ? (no it's not)70Janis Papanagnou
17 Mar 26  i  ii     i i   `* Re: Isn't that beauty ? (no it's not)69Bart
17 Mar 26  i  ii     i i    `* Re: Isn't that beauty ? (no it's not)68Janis Papanagnou
17 Mar 26  i  ii     i i     `* Re: Isn't that beauty ? (no it's not)67Bart
18 Mar 26  i  ii     i i      `* Re: Isn't that beauty ? (no it's not)66Janis Papanagnou
18 Mar 26  i  ii     i i       +* Re: Isn't that beauty ? (no it's not)64Michael S
18 Mar 26  i  ii     i i       i+* Re: Isn't that beauty ? (no it's not)4Janis Papanagnou
18 Mar 26  i  ii     i i       ii`* Re: Isn't that beauty ? (no it's not)3Bart
18 Mar 26  i  ii     i i       ii `* Re: Isn't that beauty ? (no it's not)2Waldek Hebisch
19 Mar 26  i  ii     i i       ii  `- Re: Isn't that beauty ? (no it's not)1Bart
18 Mar 26  i  ii     i i       i`* Re: Isn't that beauty ? (no it's not)59David Brown
18 Mar 26  i  ii     i i       i +* Re: Isn't that beauty ? (no it's not)31Janis Papanagnou
18 Mar 26  i  ii     i i       i i+- Re: Isn't that beauty ? (no it's not)1Janis Papanagnou
19 Mar 26  i  ii     i i       i i+* Re: Isn't that beauty ? (no it's not)27David Brown
19 Mar 26  i  ii     i i       i ii+* Re: Isn't that beauty ? (no it's not)11Michael S
19 Mar 26  i  ii     i i       i iii+* Re: Isn't that beauty ? (no it's not)8David Brown
20 Mar 26  i  ii     i i       i iiii`* Re: Isn't that beauty ? (no it's not)7Janis Papanagnou
20 Mar 26  i  ii     i i       i iiii `* Re: Isn't that beauty ? (no it's not)6Keith Thompson
20 Mar 26  i  ii     i i       i iiii  `* Re: Isn't that beauty ? (no it's not)5Janis Papanagnou
20 Mar 26  i  ii     i i       i iiii   +* Re: Isn't that beauty ? (no it's not)2Bonita Montero
20 Mar 26  i  ii     i i       i iiii   i`- Re: Isn't that beauty ? (no it's not)1Janis Papanagnou
20 Mar 26  i  ii     i i       i iiii   `* Re: Isn't that beauty ? (no it's not)2Keith Thompson
21 Mar 26  i  ii     i i       i iiii    `- Re: Isn't that beauty ? (no it's not)1Janis Papanagnou
19 Mar 26  i  ii     i i       i iii`* Re: Isn't that beauty ? (no it's not)2Bonita Montero
19 Mar 26  i  ii     i i       i iii `- Re: Isn't that beauty ? (no it's not)1Michael S
20 Mar 26  i  ii     i i       i ii`* Re: Isn't that beauty ? (no it's not)15Janis Papanagnou
20 Mar 26  i  ii     i i       i ii `* Re: Isn't that beauty ? (no it's not)14David Brown
20 Mar 26  i  ii     i i       i ii  +- Re: Isn't that beauty ? (no it's not)1Janis Papanagnou
20 Mar 26  i  ii     i i       i ii  +* Re: Isn't that beauty ? (no it's not)3Michael S
22 Mar04:39  i  ii     i i       i ii  i`* Re: Isn't that beauty ? (no it's not)2Janis Papanagnou
22 Mar07:33  i  ii     i i       i ii  i `- Re: Isn't that beauty ? (no it's not)1Michael S
20 Mar 26  i  ii     i i       i ii  `* Re: Isn't that beauty ? (no it's not)9DFS
21 Mar 26  i  ii     i i       i ii   +* Re: Isn't that beauty ? (no it's not)5Janis Papanagnou
21 Mar 26  i  ii     i i       i ii   i`* Re: Isn't that beauty ? (no it's not)4DFS
21 Mar15:42  i  ii     i i       i ii   i +* Re: Isn't that beauty ? (no it's not)2Bart
22 Mar04:57  i  ii     i i       i ii   i i`- Re: Isn't that beauty ? (no it's not)1Janis Papanagnou
22 Mar04:50  i  ii     i i       i ii   i `- Re: Isn't that beauty ? (no it's not)1Janis Papanagnou
21 Mar15:39  i  ii     i i       i ii   `* Re: Isn't that beauty ? (no it's not)3David Brown
19 Mar 26  i  ii     i i       i i`* Re: Isn't that beauty ? (no it's not)2Waldek Hebisch
19 Mar 26  i  ii     i i       i `* Re: Isn't that beauty ? (no it's not)27Michael S
25 Mar01:45  i  ii     i i       `- Re: Isn't that beauty ? (no it's not)1Tristan Wibberley
17 Mar 26  i  ii     i +* Re: Isn't that beauty ? (no it's not)10DFS
17 Mar 26  i  ii     i `* Re: Isn't that beauty ? (no it's not)4Bonita Montero
14 Mar 26  i  ii     `* Re: Isn't that beauty ? (no it's not)4Bart
13 Mar 26  i  i+* Re: Isn't that beauty ? (no it's not)15DFS
13 Mar 26  i  i+* Re: Isn't that beauty ? (no it's not)2Bonita Montero
13 Mar 26  i  i`* Re: Isn't that beauty ? (no it's not)4Bonita Montero
13 Mar 26  i  +* Re: Isn't that beauty ? (no it's not)2Bonita Montero
13 Mar 26  i  +- Re: Isn't that beauty ? (no it's not)1Bonita Montero
13 Mar 26  i  `* Re: Isn't that beauty ? (no it's not)4Bart
21 Mar 26  `* Re: Isn't that beauty ? (no it's not)6Tim Rentsch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal