brain

tamnd's digital brain — notes, problems, research

41641 notes

TAOCP 2.3.1 Exercise 20

Algorithm `T` uses an auxiliary stack `A` in consecutive memory locations.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.3.1 Exercise 15

Let a node $P$ of a threaded binary tree be given.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 2.3.1 Exercise 18

The double-order traversal visits each node twice.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.3.1 Exercise 16

Let `P` point to a node of a binary tree, and consider `Q = P*`, the successor of `NODE(P)` in preorder.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.3.1 Exercise 17

We are asked to give an algorithm analogous to Algorithm `S` that determines the preorder successor `P*` of a node `P` in a threaded binary tree with a list head as in `(8), (9), (10)`.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.3.1 Exercise 13

A postorder traversal must process a node only after both of its subtrees have been traversed.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.3.1 Exercise 11

Let $B_n$ denote the number of binary trees with $n$ nodes.

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 2.3.1 Exercise 14

In the representation (2), each node contains exactly two links, `LLINK` and `RLINK`.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.3.1 Exercise 12

We aim to construct an algorithm analogous to Algorithm `T` that traverses a binary tree in _preorder_, visiting each node exactly once, and then prove its correctness by induction on the number of no...

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.3.1 Exercise 8

Let the nodes of a binary tree be distinct.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.3.1 Exercise 9

Let a binary tree with `n` nodes be traversed using Algorithm `T`.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 2.3.1 Exercise 10

The stack grows only in step `T3`, where the current value of `P` is pushed onto `A` and then `P` is replaced by `LLINK(P)`.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.3.1 Exercise 7

Let the preorder of the binary tree be $u_1 u_2 \dots u_n$ and the inorder be $v_1 v_2 \dots v_n$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.3.1 Exercise 6

Let a binary tree have $n$ nodes, with preorder sequence u_1 u_2 \dots u_n and inorder sequence

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 2.3.1 Exercise 5

Let the representation of a node be the binary string $\alpha$, where the root is represented by `"1"`, the left child of $\alpha$ is $\alpha0$, and the right child is $\alpha1$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.3.1 Exercise 4

Let us define the new traversal order recursively, as in the exercise: 1.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.3.1 Exercise 1

[Section 2.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 2.3.1 Exercise 3

The statement claims that "The terminal nodes of a binary tree occur in the same relative position in preorder, inorder, and postorder.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 2.3.1 Exercise 2

Let `T` denote the root of the binary tree in the figure.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 2.3 Exercise 21

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 20

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 22

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 18

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 19

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 17

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 13

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 15

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 16

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 14

[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 8

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 7

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 9

[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 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 5

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 6

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 2

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3 Exercise 1

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 24

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 20

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 22

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 21

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 23

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 17

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 19

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 18

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 16

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 13

Circular lists are used in Fig.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 14

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 15

[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 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 9

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 7

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 6

[Section 2.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.2.6 Exercise 8

[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 5

[Section 2.

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
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
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 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 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 10

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

taocpmathematicsalgorithmsvolume-1project
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 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 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 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 2

A deque requires efficient insertion and deletion at both ends.

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.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 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 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 17

Let a polynomial be represented as in Section 2.

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 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 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 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 9

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

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 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 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 4

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

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 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 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 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 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 26

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

taocpmathematicsalgorithmsvolume-1hard