% CHANGES TO VOLUME 3 OF THE ART OF COMPUTER PROGRAMMING % % Copyright (C) 2022,2023 by Donald E. Knuth % This file may be freely copied provided that no modifications are made. % All other rights are reserved. % % Three levels of changes to the books are distinguished here: % % "\bugonpage" introduces the correction of an error; % "\amendpage" introduces new material for future editions; % "\improvepage" introduces ameliorations of lesser importance. % % (Changes introduced by \improvepage do not appear in the hardcopy listing.) % % Also, "\planforpage" introduces some of the author's half-baked intentions. % % NOTE: TO PUT THE INDEX ON A SEPARATE PAGE, RUN THIS WITH THE COMMAND LINE % tex "\let\indexeject+ \input err3" \newif\ifall % \alltrue means show the trivial items too \relax % hook \def\vertical{|} \def\inref#1 #{\expandafter\def\csname\vertical#1\endcsname} \catcode`|=\active \let|\inref \input \jobname.ref \catcode`|=12 \input taocpmac % use the format for TAOCP, with modifications below \def\becomes{\ifmmode\ \hbox\fi{\manfnt y}\ } % wiggly arrow indicates a change \def\bugonpage#1.#2 #3 (#4) { \medbreak\defaultpointsize \line{\kern-5pt\llap{\manfnt x}% print a black triangle in left margin {\bf Page #2}\enspace #3 \leaders\hrule\hfill\ \eightrm\date#4.} \nobreak\smallskip\iftrue\noindent} \def\amendpage#1.#2 #3 (#4) { \medbreak\defaultpointsize \line{\kern-5pt{\bf Page #2}\enspace #3 \leaders\hrule\hfill\ \eightrm\date#4.} \nobreak\smallskip\iftrue\noindent} \def\improvepage#1.#2 #3 (#4) {\ifall \medbreak\ninepoint \line{\kern-6pt{\sl Page #2\enspace #3\/} \leaders\hrule\hfill\ \eightrm\date#4.} \nobreak\smallskip\noindent} \def\planforpage#1.#2 #3 (#4) { \medbreak\defaultpointsize \line{\kern-5pt{\bf Page #2}\enspace #3 \leaders\hbox to 5pt{\hss.\hss}\hfill\ \eightrm\date#4.} \nobreak\smallskip\begingroup\let\endchange=\endgroup\sl\noindent} \let\endchange=\fi \def\nl{\par\noindent} \def\nlh{\par\noindent\hangit} \def\hangit{\hangindent2em} \def\cutpar{{\parfillskip=0pt\par}} \def\date#1.#2.#3.{% convert "yy.mm.dd." to "dd Mon 19yy" #3 \ifcase#2\or Jan\or Feb\or Mar\or Apr\or May\or Jun\or Jul\or Aug\or Sep\or Oct\or Nov\or Dec\fi \ \ifnum #1<97 \hundred#1\else19#1\fi} \def\hundred{20} % the "century" for dates before '97 \def\ex #1. [#2]{\ninepoint \textindent{\bf#1.}[{\it#2\/}]\kern6pt} \def\EX #1. [#2]{\ninepoint \textindent{\llap{\manfnt x}\bf#1.}[{\it#2\/}]\kern6pt} \def\foottext#1{\medskip \hrule height\ruleht width5pc \kern-\ruleht \kern3pt \eightpoint \smallskip\textindent{#1}} \def\volheadline#1{\line{\cleaders\hbox{\raise3pt\hbox{\manfnt\char'36}}\hfill \titlefont\ #1\ \cleaders\hbox{\raise3pt\hbox{\manfnt\char'36}}\hfill}} \def\refin#1 {\let|\inref \input #1.ref \let|\crossref} \let\defaultpointsize=\tenpoint %%%%%%%%%%%%%% opening remarks %%%%%%%%%%%%%%%%%%%%%%%% \def\lhead{INTRODUCTION} \let\rhead=\lhead \titlepage \volheadline{THE ART OF COMPUTER PROGRAMMING} \bigskip \volheadline{ERRATA TO VOLUME 3 (after 2021)} \bigskip \noindent This document is a transcript of the notes that I have been making in my personal copy of {\sl The Art of Computer Programming}, Volume~3 (second edition, 45th printing) since it was first printed in 2022. Previous errata are recorded in another file `{\tt all3-pre.ps}'. \ifall Four levels of updates\dash---``errors,'' ``amendments,'' ``plans,'' and ``improvements''\dash---appear, indicated by four \else Three levels of updates\dash---``errors,'' ``amendments,'' and ``plans''\dash---appear, indicated by three \fi different typographic conventions: \begingroup\def\hundred{17} \bugonpage 0.666 line 1 (76.07.04) Technical or typographical errors (aka bugs) are the most critical items, so they are flagged with a `\thinspace{\manfnt x}\thinspace' preceding the page number. The date on which I first was told about the bug is shown; this is the effective date on which I paid the finder's fee. The necessary corrections are indicated in a straightforward way. If,~for example, the book says `$n$' where it should have said `$n+1$', the change is shown thus: \smallskip $n$ \becomes $n+1$ \endchange \amendpage 0.666 line 2 (89.07.14) Amendments to the text appear in the same format as bugs, but without the~`\thinspace{\manfnt x}\thinspace'. These are things I wish I had known about or thought of when I wrote the original text, so I added them later. The date is the date I drafted the new text. \endchange \def\hundred{19} \planforpage 0.666 line 3 (17.11.20) Plans for the future represent a third kind of item. In such notes I~sketched my intentions about things that I wasn't ready to flesh out further when I~wrote them down. You can identify these items because they're written in slanted type, and preceded by a bunch of dots `\hbox to 6em{\leaders\hbox to 5pt{\hss.\hss}\hfill}' leading to the date on which I recorded the plan in my files. \endchange \improvepage 0.666 line 4 (38.01.10) The fourth and final category\dash---indicated by page and line number in smaller, slanted type\dash---consists of minor corrections or improvements that most readers don't want to know about, because they are so trivial. You wouldn't even be seeing these items if you hadn't specifically chosen to print the complete errata list in all its gory details. Are you sure you wanted to do that? \endchange \endgroup \ifall\else\medskip\ninepoint My personal file of updates also includes a fourth category of items, not shown in this list. They are miscellaneous minor corrections or improvements that most readers don't want to know about, because they are so trivial. If you really want to see all of the gory details, you can download the full list from Internet webpage $$\.{http://www-cs-faculty.stanford.edu/\char`\~knuth/taocp.html}$$ by selecting the ``long form'' of the errata. \fi \medskip \tenpoint My shelves at home are bursting with preprints and reprints of significant research results that I want to digest and summarize, where appropriate, in the ultimate edition of Volume~3. I didn't do that in the second edition because I would surely have to do it over again later: New results continue to pour forth at a great rate, and I will have time to rewrite that volume only~once. Volumes 4 and~5 need to be finished first. So I've put most of my effort so far into writing up those parts of the total picture that seem to have converged to their near-final form. It follows, somewhat paradoxically, that the updates in this document are most current in the areas where there has been least activity. On the other hand I do believe that the changes listed here bring Volume~3 completely up to date in two respects: (1)~All of the research problems in the previous edition\dash---i.e., all exercises that were rated 46 and above\dash---have received new ratings of 45 or less whenever I learned of a solution; and in such cases, the answer now refers to that solution. (2)~All of the historical information about pioneering developments has been amended whenever new details have come to my attention. \beginconstruction The ultimate, glorious, 100\% perfect editions of Volumes 1--4A are works in progress. Please let me know of any improvements that you think I ought to make. Send your comments either by snail mail to D.~E. Knuth, Computer Science, Gates Building 4B, Stanford University, Stanford CA~94305-9045, or by email to {\tt taocp{\char`\@}cs.stanford.edu}. (Use email for book suggestions only, please\dash---all other correspondence is returned unread to the sender, or discarded, because I have no time to read ordinary email.) Although I'm working full time on Volume~4B these days, I~will try to reply to all such messages within a year of receipt. Current news about {\sl The Art of Computer Programming\/} is posted on $$\.{http://www-cs-faculty.stanford.edu/\char`~knuth/taocp.html}$$ and updated regularly. \par\endconstruction \rightline{\dash---Don Knuth, February 2022} \bigskip \bigskip {\quoteformat Writing a series like {\rm The Art of Computer Programming} is similar to painting the Forth Rail Bridge. No sooner is it finished than the job must be started again. \author MALCOLM CLARK (1992) % A plain TeX primer, Oxford University Press, page 7 \bigskip\bigskip The time when\/ {\rm The Guardian} ceases to make mistakes altogether is not, at the moment, foreseeable. \author IAN MAYES (1998) % quoted in IHT, 17 Feb 98, p5 % he is Reader's Editor of the Manchester Guardian \vfill\eject } \def\today{\number\day\space\ifcase\month\or January\or February\or March\or April\or May\or June\or July\or August\or September\or October\or November\or December\fi \space\number\year} %%%%%%%%%%%%%%% CHANGES FOR VOLUME 3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \def\lhead{CHANGES TO VOLUME 3: SORTING AND SEARCHING} \let\rhead=\lhead \titlepage \volheadline{SORTING AND SEARCHING} \bigskip \rightline{Copyright \copyright\ 2022, 2023 Addison\with Wesley} \rightline{Last updated \today} \bigskip \rightline{\sl Most of these corrections have already been made in recent printings.} \smallskip \let\defaultpointsize=\tenpoint \bugonpage 3.93 in Table 5 for increments `4 2 1' (23.03.15) $274.42u$ \becomes $274.41u$ \endchange \bugonpage 3.95 lines $-5$ and $-4$ (23.03.12) using the quantity $\lfloor2.25h_s\rfloor$ in place of $3h_s$ in~\eq(12); \becomes\nl using the formula $h_s=\smash{\bigl\lfloor{4\over5} \bigl({9\over4}^{s+\?1}-\nobreak1\bigr)\bigr\rfloor}$; \endchange \amendpage 3.179 new quotation for middle of page (23.06.21) {\quoteformat % [Porro] methodus quia quis brevissamo tempore & ordine optimo % indicca conficiat, huiusmodi est. To do this most quickly and arranged optimally, use this method. % Quaecunque in indicem referre libuerit, Write down whatever is to appear in the index, % omnia ut primum se obtulerint, % nulla ordinis ratione habita in charta describantur, as soon as it presents itself, without any regard for order, % ab altera tantum facie, ut altera nuda relinquatur. ... using one side of a sheet of paper, leaving the other side blank. .\thinspace.\thinspace. % [Tandem] omnia descripta forfice dissecabis, Cut everything into pieces with scissors, and divide the slips % dissecta quo volueris ordine divides, into the desired order, first into large parts, % primum in maiores partes, deinde subdivides semel aut iterum, % vel quotiescunque opus fuerit. ... then subdividing once or twice, or as often as needed. .\thinspace.\thinspace. % Ubi plurimae schedulae fuerint, saepius subdividere suaserim: If there are many slips, I recommend subdividing more often: % sic enim omnia facilius et minori confusione peragentur, ... all will then be easier to sort, with less confusion. \author CONRAD GESSNER, {\sl Pandect\ae\/} (1548) % right column of folio 19v, near the beginning of volume one % found at MDZ, M\"unchener DigitaliserungsZentrum % www.digitale-sammlungen.de/en/view/bsb10145114?page=64,65 } \endchange \amendpage 3.192 line 16 (22.08.12) {\sl Vychisl.\ Matem.\ i Matem.\ Fiziki\/ \bf 62} \becomes {\sl Vychisl.\ Matem.\ i Matem.\ Fiziki\/ \bf 61} \endchange \bugonpage 3.224 line 1 below Fig.\ 48 [only in 2021 and 2022 printings] (23.03.17) ge the sorted result \becomes get the sorted result \endchange \bugonpage 3.369 line $-19$ (23.02.04) need to replenished \becomes need to be replenished \endchange \bugonpage 3.379 line 3 for exercise 27 (23.04.10) \ninepoint we throw $m_k$ balls into urns $(X_k+j)\mod n$ \becomes we throw a ball into urn $(X_k+j)\mod n$ \endchange \amendpage 3.457 new rating for exercise 29 (23.11.11) \ninepoint [{\it40\/}] \becomes [{\it30}] \endchange \bugonpage 3.478 line $-14$ (23.05.26) 540--546 \becomes 540--545 \endchange \bugonpage 3.518 line 12 (22.11.01) 461--471 \becomes 461--472 \endchange \amendpage 3.534 line 2 (22.02.06) the algorithm terminates. \becomes set $N\gets N-1$ and terminate the algorithm. \endchange \let\defaultpointsize=\ninepoint % get ready for answer pages \bugonpage 3.612 line $-5$ of answer 33 (22.11.10) 40--70 \becomes 49--70 \endchange \amendpage 3.615 line $-2$ of answer 45 (22.11.10) {\bf A114} (2007) \becomes {\bf A114} (2007), 211--234 \endchange \bugonpage 3.642 in answer 16 (22.05.22) line 7: $A_n=\lfloor\lg n\rfloor/n+$ \becomes $A_1=0$ and $A_n=\lfloor\lg n\rfloor/n+$\nl line 9: $(2^{l+1}-2)$ \becomes $(2^{l+1}-l-2)$ \endchange \improvepage 3.657 line 2 of answer 28 (23.11.11) optimal \becomes optimum \endchange \bugonpage 3.657 replacement for lines 4 and following of answer 31 (23.11.12) \noindent sorted in 3 more comparison-exchange operations. On the other hand the following tree, constructed by Filip Stappers in 2023, achieves the desired bound (and perhaps also the minimum {\it average\/} number of comparison-exchanges, namely $840/120=7$):\par \nobreak\smallskip\line{\enspace\epsfbox{\figdir/v3.6310}\hfil \vbox{\hbox{\vtop{\kern0pt\epsfbox{\figdir/v3.6311}}\kern-6pt \vtop{\kern0pt\epsfbox{\figdir/v3.6312}} \ \vtop{\kern0pt\epsfbox{\figdir/v3.6313}}}\kern0pt}\enspace} \endchange \amendpage 3.657 new answer (23.11.11) \ans32. Filip Stappers has shown that $S_e(n)=S(n)$ for $n=6$ and $n=7$. \endchange \bugonpage 3.659 in answer 12 (23.05.01) line 2: $\beta:X_{n-k}$ \becomes $\beta:X_{n+1-k}$ \nl line 4: $Y_r=X_{r-k}$ \becomes $Y_r=X_{r+k}$ \endchange \bugonpage 3.660 new answer {(and remove this citation from answer 22)} (23.03.21) \ans18. See \v{L}.~Koll\'ar, {\sl Computers and Artificial Intelligence\/ \bf5} (1986), 335--344. \endchange \bugonpage 3.711 replacement for answer 29 (23.11.11) \ans29. It is a degenerate tree (see exercise 5) with \.{THIS} at the top, \.{THE} at the bottom, needing 22.907 comparisons for an average successful search. \par Douglas A.\ Hamilton has proved that some degenerate tree is always worst. There\-fore, by exercise 6.1--14, we can find pessimal binary search trees in $O(n\log n)$ steps.\tighten \endchange \bugonpage 3.719 in answers 1 and 2 (23.05.01) {\fiverm 223 \becomes 233} (in the root node) \endchange \expandafter\ifx\csname indexeject\endcsname\relax\else\vfill\eject\fi \amendpage 3.759 and following (22.02.01) Miscellaneous changes to the existing index of Volume~3 are collected here, including corrections and amendments to the old entries as well as new entries that are occasioned by the new material. Thus, the lines of the full index that have changed serve also as an index to the present document. However, when a correction or amendment has caused an old index entry to be deleted, the deletion is usually not indicated. \input exotic \begindoublecolumns \indexformat \gdef\Uni1.08:{\bitmap24:1.08:} \hangindent 2em Analysis of algorithms, 3, 77--78, 80, 82, 85--95, 100--105, 108--109, 118--122, 140, 152--158, 161--162, 167--168, 174--177, 185--186, 255--256, 259--266, 274--279, 285--287, 294--299, 330--335, 339--343, 379, 382, 387--388, 397--408, 412--413, 424--425, 430--431, 454--458, 466--471, 479--480, 485--486, 490, 500--512, 524--525, 534--539, 543--544, 552--557, 565--566, 576, 619, 642--643, \also Complexity analysis. % 48th Gessner, Conrad, 179. % 48th Stappers, Filip Jan Jos, 657. % 48th \vfill \enddoublecolumns \endchange \bye [The next printing will be the 49th.] Not mentioned above: page 62 line -9: ), so -> ). So page 568: Reference -> \em Reference page 656 is affected by change to 657 page 704, line -5 of answer 18, remove spurious comma after (2) page 726, line 2 of answer 26, \approx instead of = 0.28879 page 741, line 3 of answer 67, \tt [ and ] ARTICLES "TO APPEAR" THAT ARE STILL PENDING: Jannis Harder on optimum sorting networks n=11,12 (in arXiv; now published?)