brain

tamnd's digital brain — notes, problems, research

43815 notes

TAOCP 2.2.2 Exercise 16

Let the memory consist of locations $L_0 < L \le L_\infty$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.2 Exercise 17

A correct proof must introduce a coupling invariant that controls how the two executions can differ.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 2.2.2 Exercise 14

For fixed $n$, the multinomial vector satisfies the multivariate central limit theorem.

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 2.2.2 Exercise 13

Let $S_n=k_1(n)+k_2(n)$ and $D_n=k_1(n)-k_2(n)$.

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 2.2.2 Exercise 15

We restart from the definitions and construct a **valid Monte Carlo experiment** that faithfully simulates both Algorithm $G$ and the earlier **one-by-one shifting algorithm**, then describe how to es...

taocpmathematicsalgorithmsvolume-1project
TAOCP 2.2.2 Exercise 12

Let $a_1,\ldots,a_m$ be independent choices with $\Pr{a_j=1}=\Pr{a_j=2}=1/2$.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 2.2.2 Exercise 11

The mathematical model of Exercise 9 assigns a random sequence of stack operations and defines the total number of moves as a sum of contributions from individual insertions, where each insertion may...

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 2.2.2 Exercise 9

Let the model in the text generate a random sequence a_1,a_2,\dots,a_n, where each $a_i$ is chosen independently and uniformly from $\{1,2,\dots,m\}$.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 2.2.2 Exercise 10

Let $m$ be the number of items $a_1, a_2, \ldots, a_m$, where each $a_j \in {1,2,\ldots,n}$.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 2.2.2 Exercise 6

The previous solution failed because it replaced the actual state of the memory in Fig.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 2.2.2 Exercise 8

The key point of the exercise is that the _global memory management_ (Algorithm G with rules (9), (10), and repacking) is unchanged in spirit: it still allocates contiguous blocks to each list and rep...

taocpmathematicsalgorithmsvolume-1hard
TAOCP 2.2.2 Exercise 7

The variable `OLDTOP[j]` is defined as the value of `TOP[j]` immediately after the previous allocation of memory.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 2.2.2 Exercise 2

We extend the circular array representation $X[1],\ldots,X[M]$ used in (6a) and (7a), with pointers $F$ (front) and $R$ (rear), where the queue is empty exactly when $F = R$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.2 Exercise 3

Let (8) denote the standard MIX sequence that performs table access via a relocatable base and indexing, of the form \texttt{LD1 I},\quad \texttt{LDA BASE},\quad \texttt{STA *+1},\quad \texttt{LDA *,1...

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.2 Exercise 4

We adopt the MIX indirect addressing semantics from the extension in Exercise 3: - An effective address $a$ may be modified by index additions $rI_i$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.2 Exercise 5

Let MIX effective address modification be governed by an $I$-field taking values $0,1,\dots,7$, where $0,\dots,6$ are ordinary modifications and $7$ denotes indirect addressing.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 2.2.1 Exercise 14

A queue is a linear list in which insertions occur at the rear and deletions occur at the front, using Knuth’s notation (4) and (5).

taocpmathematicsalgorithmsvolume-1hard
TAOCP 2.2.1 Exercise 13

We correct the solution by fixing the Baxter characterization and by making the deque–Baxter correspondence explicit as a cited theorem rather than an informal claim.

taocpmathematicsalgorithmsvolume-1math-research
TAOCP 2.2.1 Exercise 12

Let $a_n$ denote the number of permutations of $12\ldots n$ obtainable by a stack, as in Exercise 4.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 2.2.2 Exercise 1

The queue is stored in the circular array $X[1], \ldots, X[M]$ with pointers $F$ and $R$, initially $F = R = 1$.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 2.2.1 Exercise 10

A sequence of operations on an output-restricted deque consists of symbols $S$, $Q$, and $X$, applied to the input stream $1,2,\dots,n$ in that order.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 2.2.1 Exercise 8

The correct resolution is that **every permutation of $1,2,\ldots,n$ is obtainable** using an unrestricted deque, but the proof must explicitly justify why adding the largest element does not restrict...

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.1 Exercise 9

Fix a convention.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 2.2.1 Exercise 11

Let $b_n$ denote the number of permutations of $1,2,\dots,n$ obtainable by an output-restricted deque, equivalently by an input-restricted deque, as established in earlier exercises.

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 2.2.1 Exercise 7

A deque supports insertions and deletions at its ends.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.1 Exercise 4

Let $a_n$ denote the number of permutations of ${1,2,\dots,n}$ obtainable by a stack operating as in Exercise 2, where each element is pushed once and popped once.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 2.2.1 Exercise 6

Every insertion into the queue places the new element at the rear, and every deletion removes the element at the front.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.1 Exercise 5

We prove the equivalence carefully from first principles, correcting both directions.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 2.2.1 Exercise 2

A legal sequence of operations consists of reading cars $1,2,3,4,5,6$ in order, each either being pushed onto the stack or popped to output when it becomes the next required output.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 2.2.1 Exercise 1

An output-restricted deque permits insertions at both ends and deletions at only one fixed end.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 2.2.1 Exercise 3

Let a sequence of operations consist of symbols $S$ and $X$, where $S$ inserts the next input car into the stack and $X$ removes the top stack car to the output.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.1 Exercise 8

The previous solution does not implement any MIX program because it has no access to the content of steps $B1$–$B3$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.1 Exercise 9

We first restate a clean and valid MIX representation and then give a corrected program that follows MIX conventions consistently.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.1 Exercise 7

Let TOP denote the word containing the link field of the top node.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 2.1 Exercise 3

Let $TOP$ denote the address of the top card of the pile, with $TOP = 0$ representing an empty pile.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 2.1 Exercise 6

The operation $ \text{CARD} \leftarrow \text{NODE}(\text{TOP}) $ copies each field of the node at $\text{TOP}$ into the corresponding fields of the node-valued variable $\text{CARD}$.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 2.1 Exercise 5

Let the pile be represented as a linked structure of cards.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.1 Exercise 4

Let $TOP$ denote the address of the first card in the pile, and let $NEXT(X)$ denote the link field of card $X$, with value $0$ meaning “no successor.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.1 Exercise 1

Let the structure in Figure (3) consist of four nodes linked by the field $NEXT$: TOP \rightarrow N_1 \rightarrow N_2 \rightarrow N_3 \rightarrow N_4 \rightarrow NIL and suppose the figure specifies t...

taocpmathematicsalgorithmsvolume-1simple
TAOCP 2.1 Exercise 2

For any variable $V$, the expression $\mathrm{CONTENTS}(\mathrm{LOC}(V)) = V$ holds whenever $V$ denotes a storage cell in the sense of Section 2.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.4.4 Exercise 15

Let the three buffers be `BUF1`, `BUF2`, and `BUF3`, each consisting of 100 words.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.4 Exercise 16

The exercise asks for a formulation of the "green-yellow-red-purple" buffering scheme of Fig.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 1.4.4 Exercise 14

In the multiple-buffering scheme described in the text, the normal discipline is \cdots\ \text{ASSIGN}\ \cdots\ \text{RELEASE}\ \cdots\ \text{ASSIGN}\ \cdots\ \text{RELEASE}\ \cdots so that the comput...

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.4 Exercise 12

In the multiple buffering scheme, anticipated input is used: whenever a buffer is released for processing, the CONTROL coroutine immediately initiates reading of another card into a free buffer.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.4 Exercise 10

There are twelve buffer assignments in the computation sequence.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.4 Exercise 7

Subroutine (4) detects the end of a buffer by placing a sentinel in the 101st word of each buffer.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.4 Exercise 5

Let $n$ be the number of I/O devices referred to by the program, and let $T_i$ denote the time required to perform a complete unbuffered I/O operation on device $i$, for $1 \le i \le n$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.4.4 Exercise 4

Let a program process $n$ blocks of data using a single I/O device.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.4.4 Exercise 2

The unbuffered method is \texttt{OUT 1000(6); JBUS *(6).

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.4.4 Exercise 1

(a) No.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.4.4 Exercise 3

The output analogue of (4) should keep one buffer available for writing by the program while the other buffer is being written onto tape.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.3.2 Exercise 3

Writing trace output directly to a printer or similar output device forces the trace routine to compete with the traced program for that device.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.4.3.2 Exercise 4

The previous solution fails because it assumes a clean separation between “program being traced” and “tracing mechanism.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.3.2 Exercise 6

The original solution correctly removed self-exclusion, but it failed to address the essential point: MIX tracing does not inherently create recursive invocations of the tracer.

taocpmathematicsalgorithmsvolume-1project
TAOCP 1.4.3.2 Exercise 5

Let $T_A$ and $T_B$ denote two physically distinct copies of the trace routine in Section 1.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 1.4.3.2 Exercise 7

The correct construction is event-based: one output is produced exactly when a jump instruction is executed, and the output records that instruction’s location and its destination.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.3.2 Exercise 1

The critical issue is the incorrect assumption that control can be returned after restoring $rJ$ using `JMP *`.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.3.1 Exercise 8

We are asked to determine the truth of the statement: _Whenever line 010 of the simulator program is executed, we have $0 \le rI6 < \text{BEGIN}$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.3.2 Exercise 2

At each cycle the trace routine reaches location `INST` (line 34) immediately before the simulated execution of the external instruction.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 1.4.3.1 Exercise 6

The simulator maintains the state of the simulated MIX machine, including the registers `AREG`, `I1REG`, …, `I6REG`, `XREG`, `JREG`, and the special registers `CLOCK`, `OVTOG`, and `COMPI`, together w...

taocpmathematicsalgorithmsvolume-1hard
TAOCP 1.4.3.1 Exercise 5

The simulator assigns execution time $2$ to the instruction `LDA`, as shown by the entry \texttt{LDA \ \ LOAD(2)} in `OPTABLE`.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.3.1 Exercise 2

The operation code 6 corresponds to the shift group handled by the single routine `SHIFT`, entered from the switching table `OPTABLE` with execution time $2$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.3.1 Exercise 4

In the given program the label `BEGIN` performs the initialization that, in the actual MIX machine, is performed by pushing the GO button.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.4.2 Exercise 5

In the original linkage (4), only one register-save location is introduced, and only one direction of communication is protected: the contents of register $A$ are saved when control passes from one co...

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.4.2 Exercise 6

The error in the previous solution is the treatment of the resume labels.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.2 Exercise 7

The previous solution fails primarily because it is not a valid MIX program: it uses non-existent instructions, inconsistent state handling, and an incoherent coroutine structure.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 1.4.2 Exercise 4

Consider a conventional stored-program computer with a program counter $\mathrm{PC}$ and memory cells that can hold addresses.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.2 Exercise 3

We address the reviewer’s objections by rebuilding the argument from the actual structural role of the three occurrences of `CMPA PERIOD` inside `OUT`, without assuming anything global beyond what is...

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.2 Exercise 1

Short examples of coroutines tend to collapse either into ordinary sequential programs or into degenerate cases where the coroutine mechanism is not exercised.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.4.1 Exercise 7

Self-modifying code is discouraged because modern computer architectures and software systems separate the treatment of instructions and data, and this separation is essential for correctness, perform...

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.2 Exercise 2

The proposed failure analysis is incorrect because it assumes a missing or premature dependency in the initialization of `INX`.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.1 Exercise 4

We restart from correct MIX semantics in TAOCP and rebuild the solution cleanly.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.1 Exercise 5

In MIX without a J-register, subroutine linkage must be achieved by explicitly storing the return address in a general register or memory cell before transferring control to the subroutine, and then r...

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.1 Exercise 6

The original attempt fails because it tries to update memory-resident variables with `INCX`/`DECX`, which in MIX affect only register $X$.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 1.4.1 Exercise 3

Let the call `JMP MAX100` occur at location $L$.

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 1.4.1 Exercise 2

The correct replacement must reproduce the _defining semantics of_ `JSJ X` in MIX: \texttt{JSJ X: } J \leftarrow \text{address of next instruction}, \quad \text{then } \text{go to } X.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.3.3 Exercise 37

Let $\pi$ be a permutation of ${1,\ldots,n}$.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 1.4.1 Exercise 1

The previous answer failed because it replaced the TAOCP interface conventions with ad hoc parameter passing.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.3.3 Exercise 34

Let $N = m + n$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.3.3 Exercise 35

Let the array be x_0 x_1 \ldots x_{l+m+n-1} = \alpha\beta\gamma, where $\alpha$, $\beta$, and $\gamma$ are consecutive substrings of lengths $l$, $m$, and $n$, respectively.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 1.3.3 Exercise 36

Let $x_0x_1\ldots x_{l+m+n-1} = \alpha\beta\gamma$, where $\alpha = x_0\ldots x_{l-1}$, $\beta = x_l\ldots x_{l+m-1}$, and $\gamma = x_{l+m}\ldots x_{l+m+n-1}$.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 1.3.3 Exercise 33

Let m=2^{2^l},\qquad n=2^{2l+1}.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 1.3.3 Exercise 32

Stopped thinking

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.3.3 Exercise 31

Let $J_m(n)$ denote the Josephus permutation for step size $m>1$ on the positions ${1,2,\ldots,n}$.

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 1.3.3 Exercise 30

Stopped thinkingIs this conversation helpful so far?

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.3.3 Exercise 29

Let $S$ denote the perfect shuffle permutation on ${1,2,\ldots,2n}$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.3.3 Exercise 26

For each element $x$ in the underlying universe, let $t(x)$ denote the number of sets among $S_1,S_2,\ldots,S_M$ that contain $x$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.3.3 Exercise 27

Let $M = m_1 m_2 \cdots m_t$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.3.3 Exercise 24

Find the variance of the quantity $A$ that enters into the timing of Algorithm $J$.

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 1.3.3 Exercise 21

Let \alpha_1,\alpha_2,\ldots denote the numbers of cycles of lengths

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.3.3 Exercise 19

Equation (25) for the rencontres numbers gives, when $k=0$, P_{n0} = n!

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 1.3.3 Exercise 17

Let all cycles occurring in all permutations of $n$ elements be listed, including singleton cycles.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.3.3 Exercise 14

Algorithm $J$ is not defined in the provided excerpt, and the quantity $A$ in its timing analysis is also not defined within the given material.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 1.3.3 Exercise 11

Let \pi=(x_1\,x_2\,\ldots\,x_n) be a cycle.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.3.3 Exercise 10

Let the data characteristics of Program $B$ be denoted by the frequencies $A,B,\ldots,Z$ appearing in its flowchart analysis.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 1.3.3 Exercise 9

No.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.3.3 Exercise 6

Program A is analyzed in the text under the assumption that all blank words occur at the extreme right of the input.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 1.3.3 Exercise 7

The input (6) consists of five parenthesized cycles $(acfg)(bcd)(aed)(fade)(bgfae)$, so the number of input cards is X = 5.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.3.3 Exercise 8

Algorithm $B$, as described in Section 1.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.3.3 Exercise 5

The permutation `(acf)(bd)` consists of a $3$-cycle and a $2$-cycle.

taocpmathematicsalgorithmsvolume-1math-simple