Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Isn't that beauty ? (no it's not) Date: Thu, 16 Apr 2026 10:23:23 -0700 Organization: A noiseless patient Spider Lines: 71 Message-ID: <86ecke7ras.fsf@linuxsc.com> References: <10otm7r$1ntrg$1@raubtier-asyl.eternal-september.org> <10p1r1q$3hfeq$1@dont-email.me> <10p2q41$3umkh$1@raubtier-asyl.eternal-september.org> <10p2ssl$3ven8$1@dont-email.me> <10p30j2$13nd$1@raubtier-asyl.eternal-september.org> <10p30kr$13nd$2@raubtier-asyl.eternal-september.org> <10p3jgn$80c7$1@dont-email.me> <10p9q0h$2a77o$1@dont-email.me> <10pa02q$2d5us$1@dont-email.me> <10pa4eg$2dtli$5@dont-email.me> <10pa78l$2fjaa$1@dont-email.me> <10palrv$2jpeu$2@dont-email.me> <10pbf0q$2rtq3$1@dont-email.me> <10pbg8f$2spms$2@dont-email.me> <10pbhud$2tbk0$2@dont-email.me> <10pcvr2$3ednq$2@dont-email.me> <20260318112151.000021dc@yahoo.com> <10pdu8k$3o60c$1@dont-email.me> <20260319111959.0000447c@yahoo.com> <86fr57xhf2.fsf@linuxsc.com> <20260407140041.00001c9e@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Thu, 16 Apr 2026 17:23:26 +0000 (UTC) Injection-Info: dont-email.me; posting-host="998f9c1aaa61940fcd72b99783c47cae"; logging-data="1941983"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX188XAUViMBc7zj5Y8dxNQZeniP6O/v8A/g=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:b7JBQXVPGEBqx1xxfGGZtjcb16o= sha1:ilRUWS3pAQqhdJSuneYizVArp+s= Xref: csiph.com comp.lang.c:397609 Michael S writes: > On Tue, 07 Apr 2026 02:12:49 -0700 > Tim Rentsch wrote: > > > > >> My conclusions... >> >> The right place to start on sorting algorithms is with bubble >> sort, not because it's a good algorithm, but because it's the >> easiest one to show, and what is more important it's a good way >> to teach about how algorithms evolve. > > If you write it in terms of moves rather than in terms of swaps, > bubble sort is not easier than insertion and selection. A reason to use swap() is that swap is easier to understand than moves. Each swap() operation, all by itself, preserves the invariant that the array contains the same elements after the swap() is done that were there before. With code written using moves, several statements together need to be looked at to verify that they are doing the right thing. Furthermore, when used in conjunction with follows(), whenever we see the two together written like this if( follows(x,y,array) ) swap(x,y,array); we know that both (1) the array has the same elements as it did before, and (2) the "sortedness" of array elements has increased, or at least has remained unchanged. Compare that to an insertion sort written using moves, where a whole loop body (including a 'break;' no less), plus a statement after, needs to be examined to verify that it is doing something sensible. Clearly less mental effort is needed to see that the one line written above is working than what is needed for the eight lines seen in the insertion sort shown in your (much) earlier posting. >> There is no reason to use the knuth version of bubble sort. >> Compared to ordinary bubble sort the upside is small and not >> worth the downside of needing more intricate code. > > knuth version has at least one merit. You claim that in practice the > it's too rare that the merit is exercised. May be, it is true. Or may > be cases of almost sorted array with misplaced elements coming in pairs > with close proximity between peers is not that uncommon. I don't know. > But merit exist. I posted a performance comparison of several sorts including knuth bubble sort. It's true that knuth bubble sort is better than plain bubble sort. But it's still awful compared to the even simpler gnome sort. > OTOH, 'ordinary bubble sort' has no merits at all relatively to simple > insertion sort. Simple bubble sort is easier to understand than insertion sort. For those who don't like bubble sort, there is gnome sort, which is even simpler than bubble sort, and actually has better performance. And, if people will forgive me, it's only a short leap to get to leaping gnome sort, which has better performance still. > BTW, thank you for 'boustrophedon'. Not that there is a > serious chance that I will remember the word tomorrow or even > tonight, But hopefully I'd remember that such word exists. It comes from Greek, meaning roughly "ox plow turning". Maybe that will help you remember; I think it does for me.