brain

tamnd's digital brain — notes, problems, research

43815 notes

TAOCP 2.3 Exercise 16

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 14

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 13

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 10

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 12

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 11

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 9

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 8

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 7

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 5

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 4

In a conventional tree diagram with the root drawn at the top, each node at level $k+1$ is placed below its parent at level $k$.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 6

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 3

Proceed by induction on the number of nodes in the tree.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 1

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 2

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 24

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 22

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 20

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 23

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 21

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 18

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 19

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 17

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 15

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 13

Circular lists are used in Fig.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 16

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 14

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 9

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 11

Each of the $200$ rows contains at most $4$ nonzero entries, so the total number of nonzero matrix elements stored as nodes is at most 200 \cdot 4 = 800.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 12

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 10

We reorganize the personnel table so that every attribute list is an **inverted list sorted by a single fixed total order on persons**, for example by a unique person index $1,2,\dots,n$.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 6

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 7

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 8

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 5

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 3

The lexicographic order used for $0 \le k \le j \le n$ is unchanged when the index set is shifted to $1 \le k \le j \le n$; only the origin of the indexing changes.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 4

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 2

Define new indices $I'_r = I_r - l_r$ for $1 \le r \le k$.

taocpmathematicsalgorithmsvolume-1
CF 105348F - Sub Permutation

We are given a permutation of size $n$, and we need to consider every contiguous subarray. For each subarray, we take its elements and replace them with their relative ranks inside that subarray.

codeforcescompetitive-programming
TAOCP 2.2.5 Exercise 12

The simulation program maintains two principal dynamic structures, `QUEUE[IN]` and `ELEVATOR`, in which individual users are inserted and later removed according to events generated by the coroutines.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.6 Exercise 1

Let each node of $A$ occupy two consecutive memory words and suppose lexicographic (row-major) order is used.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.5 Exercise 10

For each floor $j$, record the behavior of the elevator under the following circumstances: 1.

taocpmathematicsalgorithmsvolume-1project
TAOCP 2.2.5 Exercise 11

Let $V[1], \dots, V[n]$ be the variables of the system, and let a step of the simulation specify a small subset of these variables to be updated simultaneously.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.5 Exercise 9

The `DECISION` subroutine is called whenever the elevator is in a dormant condition and a new request may require a change of state.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.5 Exercise 8

Step `E8` is the action that occurs after the elevator has moved one floor in its current direction.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.5 Exercise 7

The statement `JANZ CYCLE` at line 154 was intended to skip the "give up" activity `U4` for a user if the elevator had already arrived at the user's floor.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.5 Exercise 6

The desired change is that a user waiting on floor `IN` should enter the elevator only if the elevator is accepting passengers whose desired direction agrees with the user's destination.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.5 Exercise 5

The scenario given concerns the discrete simulation of the Caltech Mathematics building elevator, using the routines described in Section 2.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.5 Exercise 4

Activity `E9` in the elevator coroutine is a scheduled action that occurs after the completion of certain steps in the elevator's operation, specifically following step `E6` (door-closing and possible...

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.5 Exercise 3

To demonstrate that the elevator system requires three independent binary variables per floor, we must exhibit sequences of button presses that show each variable can be set or cleared independently o...

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.5 Exercise 1

In representation (1) of a doubly linked list, there are distinguished variables `LEFT` and `RIGHT` giving the locations of the leftmost and rightmost nodes, respectively.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.5 Exercise 2

A deque requires efficient insertion and deletion at both ends.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.4 Exercise 15

We are asked to design an efficient algorithm to "erase" an entire circular list by placing all its nodes onto the `AVAIL` stack.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.4 Exercise 18

Each node $x_i$ stores a single link field $\mathrm{LINK}(x_i)$ defined as the exclusive-or of the addresses of its two neighbors in the circular order.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.4 Exercise 17

Let a polynomial be represented as in Section 2.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.4 Exercise 16

Let $p$ denote the number of nonzero terms in $P$, $m$ the number of nonzero terms in $M$, and $q$ the number of nonzero terms in the initial polynomial stored in $Q$.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 2.2.4 Exercise 13

Let $P$ denote the pointer value initially in $rI1$, which points to a node of a circular list representation of a polynomial.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.4 Exercise 14

A polynomial equal to $0$ is represented by a single special node, called the terminating node, whose fields satisfy $\mathrm{COEF} = 0$ and $\mathrm{ABC} = -1$, and whose link field points to itself...

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.4 Exercise 12

Let $P$ contain $n$ nonzero terms, and let $\operatorname{polynomial}(Q)=0$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.4 Exercise 11

We are asked to create a subroutine `COPY` that produces a complete duplicate of a given polynomial represented as a circularly linked list with a sentinel node, preserving the original list and retur...

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.4 Exercise 9

Algorithm `A` does **not** work properly when `P = Q`.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.4 Exercise 10

We wish to adapt Algorithms `A` (addition) and `M` (multiplication) for polynomials in a single variable $x$, allowing exponents up to $b^3 - 1$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.4 Exercise 8

The list representation used in Algorithm $A$ is singly linked, so the link field of a node gives access only to its successor.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 2.2.4 Exercise 7

The decreasing order of the `ABC` fields makes it possible to compare the current terms of two polynomials and determine immediately whether the exponents are equal, or whether one polynomial contains...

taocpmathematicsalgorithmsvolume-1simple
TAOCP 2.2.4 Exercise 6

The previous solution used a linear NIL-terminated list, but in TAOCP Section 2.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.4 Exercise 5

Let the given circular list be nonempty and let $PTR$ point to its rightmost node, so that $F = LINK(PTR)$ is the leftmost node in the cyclic order induced by following `LINK` pointers.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.4 Exercise 4

In representation (4), a circular linked list is maintained with a distinguished head node `HEAD`.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.4 Exercise 2

Let L_1 = (a_1, a_2, \dots, a_k), \qquad PTR_1 = a_k, so that

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.4 Exercise 3

Let the circular list be a directed cycle in which each node has exactly one outgoing link.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.4 Exercise 1

Let the proposed convention be that an empty circular list is represented by $PTR = LOC(PTR)$, while a nonempty list is represented as in the text, where $PTR$ is the address of the rightmost node and...

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.3 Exercise 28

We restart the argument from the correct fixed-point formulation and give a complete retrograde analysis that also accounts for positions that are neither winning nor losing.

taocpmathematicsalgorithmsvolume-1project
TAOCP 2.2.3 Exercise 27

The previous solution fails because it never commits to a _true MIX-level representation_: all structure was symbolic, fields were abstract, and control flow relied on pseudocode.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.3 Exercise 25

Let the directed graph be $G=(S,E)$ where $S$ is the set of nodes and $E$ is the set of ordered pairs $(u,v)$ indicating an edge $u \to v$.

taocpmathematicsalgorithmsvolume-1research
TAOCP 2.2.3 Exercise 26

For each directory node let \operatorname{SPACE}(P) denote the number of words required by subroutine $P$, and let

taocpmathematicsalgorithmsvolume-1hard
TAOCP 2.2.3 Exercise 24

The flaw in the previous solution is the introduction of an auxiliary walk that is not part of Program $T$’s state.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.3 Exercise 23

Algorithm $T$ performs a topological sort on a directed graph with vertices $1,2,\dots,n$, using the array $\text{COUNT}$ and the queue controlled by $F$ and $R$.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 2.2.3 Exercise 21

Let Algorithm $T$ process an input consisting of relations of the form $j \prec k$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.3 Exercise 22

Program $T$ becomes unsafe when an input value is used as a subscript without verification, since a negative or excessively large value of $k$ causes an access such as $X[k]$ or $\text{COUNT}[k]$ to r...

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.3 Exercise 18

Algorithm $T$ in §2.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.3 Exercise 19

In Algorithm `T`, step `T5` accesses the front element of the queue via the pointer `F` without changing the queue structure, while step `T7` performs the structural update that removes that front ele...

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.3 Exercise 20

Algorithm $T$ maintains a collection of nodes whose $\text{COUNT}$ field has just become $0$ but whose successor arcs have not yet been fully processed.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.3 Exercise 14

Let $(S,\preceq)$ be a finite partially ordered set, and let a _topological sort_ mean a linear extension of $\preceq$, i.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 2.2.3 Exercise 16

Let $S = {x_1,\ldots,x_n}$ be a finite set with a partial ordering $\preceq$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 2.2.3 Exercise 17

We restart the solution from first principles and explicitly execute Algorithm $T$ on the given input.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.3 Exercise 15

Let $S$ be a finite partially ordered set with order relation $\preceq$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 2.2.3 Exercise 11

Correcting the argument requires first fixing the fundamental mistake in the previous write-up: it is not valid to replace the given instance with a generic discussion.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.3 Exercise 10

Define the relation $\preceq$ by x \preceq y \iff (x = y \ \text{or}\ x \subset y).

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 2.2.3 Exercise 12

Let $S$ be a set of $n$ elements.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 2.2.3 Exercise 13

The reviewer’s objections remove the entire structural collapse used in the previous solution.

taocpmathematicsalgorithmsvolume-1math-research
TAOCP 2.2.3 Exercise 8

The algorithm is correct (standard in-place reversal of a singly linked list).

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.3 Exercise 7

Let $P$ be a pointer to the current node being processed, initially set to $FIRST$, let $Q$ be a pointer to the already reversed portion of the list, initially set to $\Lambda$, and let $R$ be an auxi...

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.3 Exercise 9

A relation $\preceq$ is a partial ordering on $S$ if it is reflexive, antisymmetric, and transitive.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.3 Exercise 3

Use the standard representation employed in §2.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.3 Exercise 4

The previous solution fails at the only critical requirement of the exercise: it never actually changes the return address used by `JMP 0,3`, so it cannot produce return to $rJ - 2$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.3 Exercise 5

Let the linked representation be the standard TAOCP structure with node fields $\mathrm{INFO}$ and $\mathrm{LINK}$, and with pointers $F$ and $R$ to the front and rear of the queue.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.3 Exercise 6

The flaw in the previous solution is that it still implicitly relies on evaluating $\text{LINK}(P)$ in the case where $P$ is the last node.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.3 Exercise 2

The correct solution must be rebuilt from the MIX calling convention of Section 1.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.2 Exercise 19

The stack part of the proposed solution is already correct under 0-origin indexing.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.2.3 Exercise 1

Operation (8) uses the allocation primitive $P \Leftarrow \text{AVAIL}$, which is defined in (6).

taocpmathematicsalgorithmsvolume-1simple
TAOCP 2.2.2 Exercise 18

The error in the previous solution is exactly the attempt to control the additive $O(n)$ per repacking by bounding the number of repackings.

taocpmathematicsalgorithmsvolume-1math-hard