brain

tamnd's digital brain — notes, problems, research

41348 notes

TAOCP 3.3.3 Exercise 16

We are asked to prove the identity \sum_{j=1}^{t} (-1)^{j+1} \frac{c_j^2}{m_j m_{j+1}} = \frac{1}{m_1} \sum_{j=1}^{t} (-1)^{j+1} b_j (c_j + c_{j+1}) p_{j-1}, where the sequences $(m_j)$ and $(p_j)$ co...

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.3 Exercise 12

The issue is not with the core idea of sweeping and using endpoint extrema per color.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.3 Exercise 13

Equation (28) in Section 3.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.3 Exercise 11

Let (x)=x-\lfloor x\rfloor-\tfrac12 be the centered sawtooth function and

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.3.3 Exercise 9

Hmm.

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 3.3.3 Exercise 10

Let $\sigma(h,k,c)$ be the sawtooth sum used in the TAOCP context, where the key structure is a sum over a complete residue system modulo $k$ of a shifted sawtooth expression of the form \sigma(h,k,c)...

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.3 Exercise 6

Let $h h' + k k' = 1$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.3 Exercise 8

Let D(a,b;c)=\sum_{j=0}^{c-1} \left(\!

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.3.3 Exercise 3

Hmm.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.3 Exercise 4

The problem asks for the maximum possible value of $d$ in the notation of Theorem P, given that $m = 10^{10}$ and the potency of the generator is 10.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.3 Exercise 5

From Eq.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.3 Exercise 1

**Exercise 3.

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 3.3.2 Exercise 34

The previous implementation fails because it blindly alternates the column in a zigzag without checking **preexisting cacti** in adjacent cells.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 3.3.2 Exercise 35

Let ${Y_n}$ be a binary sequence generated by the linear recurrence over $\mathbb{F}_2$ Y_n = (a_1 Y_{n-1} + \cdots + a_k Y_{n-k}) \bmod 2, with period $2^e - 1$, and initial state not the all-zero st...

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 3.3.2 Exercise 32

The statement is **false**.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.2 Exercise 33

We are asked to determine the asymptotic value of the probability that $k+1$ consecutive bits generated by Y_n = (Y_{n-1} + Y_{n-2}) \bmod 2 contain more 1s than 0s, under the conditions that $k > 2l$...

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 3.3.2 Exercise 31

Let the sequence $(Y_n)$ satisfy the recurrence Y_n = (Y_{n-21} + Y_{n-55}) \bmod 2 over $\mathbb{F}_2$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.2 Exercise 29

Let $b_{n,r,s}(m)$ be defined as in Exercise 28: it counts the number of $n$-tuples $(y_1, \ldots, y_n)$ with $0 \le y_j < m$ that have exactly $r$ equal spacings and $s$ zero spacings.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.3.2 Exercise 30

The exercise explicitly depends on results developed across Exercises 28 and 29, especially the generating functions for $b_{n,r,0}(m)$, and it asks for a fairly deep asymptotic expansion whose deriva...

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 3.3.2 Exercise 28

Let $y_1,\dots,y_n$ be i.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.3.2 Exercise 27

Let $U_1,\ldots,U_n$ be independent uniform $(0,1)$ deviates and let $S_1,\ldots,S_n$ denote their spacings in increasing order, so that $0 \le S_{(1)} \le \cdots \le S_{(n)}, \qquad \sum_{i=1}^n S_{(...

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 3.3.2 Exercise 26

Let the linear congruential sequence be X_{n+1} \equiv aX_n + c \pmod m, \qquad b=a-1, \qquad d=\gcd(m,c),

taocpmathematicsalgorithmsvolume-2
TAOCP 3.3.2 Exercise 24

Let $Y_1,\dots,Y_n$ be a cyclic sequence over $\{0,1,\dots,d-1\}$.

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 3.3.2 Exercise 25

**Exercise 3.

taocpmathematicsalgorithmsvolume-2
TAOCP 3.3.2 Exercise 21

**Exercise 3.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.3.2 Exercise 22

Algorithm P (as defined earlier in Section 3.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.3.2 Exercise 23

Let $(Y_n)$ and $(Y'_n)$ be integer sequences with period lengths $\lambda$ and $\lambda'$, respectively, and values in ${0,1,\ldots,d-1}$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.2 Exercise 20

Let the serial correlation coefficient (23) be C=\frac{N}{D}, where

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 3.3.2 Exercise 19

Let $U_0,\ldots,U_{n-1}$ be independent identically distributed random variables.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.3.2 Exercise 18

**Exercise 3.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.2 Exercise 17

Let the means of the sequences be $\bar{u} = \frac{1}{n} \sum_{0 \le k < n} U_k, \qquad \bar{v} = \frac{1}{n} \sum_{0 \le k < n} V_k,$ and define the centered sequences $U_k' = U_k - \bar{u}, \qquad V...

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.2 Exercise 15

In the maximum-of-$t$ test, the $j$th observation is V_j=\max(U_{tj},U_{tj+1},\ldots,U_{tj+t-1}).

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 3.3.2 Exercise 16

**a)** Let Z_{jt} = \max(U_j, U_{j+1}, \ldots, U_{j+t-1}).

taocpmathematicsalgorithmsvolume-1simple
TAOCP 3.3.2 Exercise 14

Let $\langle X_i \rangle = X_0, X_1, X_2, \ldots$ be a sequence of distinct numbers.

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 3.3.2 Exercise 13

Pattern (15) is the unimodal pattern x_0 < x_1 < \cdots < x_p > x_{p+1} > \cdots > x_{p+q}, on $p+q+1$ distinct elements.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.2 Exercise 10

Let $R$ denote the length of a single segment in the generalized coupon collector's test of exercise 9.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.2 Exercise 12

An ascending run is a maximal consecutive subsequence U_i,U_{i+1},\ldots,U_j such that

taocpmathematicsalgorithmsvolume-1medium
CF 104664A - Noodle Restauarant

We are given a square grid of size $n times n$, where each cell represents the annual revenue generated by a table in a restaurant. The restaurant layout is a perfect square, so the grid has exactly four corners: top-left, top-right, bottom-left, and bottom-right.

codeforcescompetitive-programming
TAOCP 3.3.2 Exercise 11

\pi = (1, 3, 5, 4, 6, 2, 7) since (9) in that section is usually this permutation.

taocpmathematicsalgorithmsvolume-1
TAOCP 3.3.2 Exercise 8

Let $Y_0, Y_1, \dots$ be independent and uniformly distributed integers between $0$ and $d-1$, with $d \ge 2$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.2 Exercise 9

Let $L$ denote the length of one coupon-collector segment produced by Algorithm C.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.2 Exercise 7

**Exercise 3.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 3.3.2 Exercise 6

Let $e = 2.71828\ldots$ and consider its expansion in an integer base $b \ge 2$, giving digits $e = \sum_{k=-1}^{\infty} e_k b^{-k}, \quad e_k \in \{0,1,\dots,b-1\},$ where $e_{-1} = 2$ for the intege...

taocpmathematicsalgorithmsvolume-1project
TAOCP 3.3.2 Exercise 4

Let $\langle U_n \rangle = U_0, U_1, U_2, \ldots$ be a sequence of independent uniform random variables on $[0,1)$, and let $0 \le \alpha < \beta \le 1$.

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 3.3.2 Exercise 3

Let ${U_j}$ be a sequence of independent and uniformly distributed random variables on $[0,1)$, and let $p = \beta - \alpha$ denote the probability that $U_j$ lies in the interval $[\alpha, \beta)$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.2 Exercise 5

Let I_j = \begin{cases} 1,& \alpha \le U_j < \beta,\\ 0,& \text{otherwise},\end{cases} and define

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.2 Exercise 1

The serial test is defined in terms of $n$ observations of pairs that are intended to behave like independent draws from the $d^2$ equally likely categories.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 3.3.2 Exercise 2

For triples, quadruples, or generally $k$ successive values, the serial test is formed by grouping the sequence $\langle Y_n \rangle$ into disjoint blocks of length $k$.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 3.3.1 Exercise 24

Let $n$ be a fixed positive integer, and let each of $n$ independent trials result in one of three categories with probabilities $p$, $q$, and $r$, satisfying $p + q + r = 1,\quad p,q,r \ge 0.$ Let $Y...

taocpmathematicsalgorithmsvolume-1project
CF 104664B - Noodle Tug of War

We are given a sequence of positive integers representing strengths of participants arranged in a line. The task is to choose a single split position such that the array is divided into a left prefix and a right suffix.

codeforcescompetitive-programming
TAOCP 3.3.1 Exercise 25

Let Y_i=\sum_{j=1}^{n}a_{ij}X_j+\mu_i,\qquad 1\le i\le m, where $X_1,\ldots,X_n$ are independent random variables with

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 3.3.1 Exercise 21

Let $X_1,\ldots,X_n$ be independent observations from a distribution function $F$, and let F_n(x)=\frac1n\#\{j:X_j\le x\}.

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 3.3.1 Exercise 22

Investigate the "improved" KS test suggested in the answer to exercise 6.

taocpmathematicsalgorithmsvolume-1hm-research
TAOCP 3.3.1 Exercise 23

Let the empirical distribution function be F_n(x) = \frac{1}{n} \sum_{i=1}^n \mathbf{1}_{\{X_i \le x\}}, and define the Kolmogorov-Smirnov statistics as in formula (13):

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.1 Exercise 20

The previous solution fails because it assumes, without justification, that the finite-$n$ Kolmogorov–Smirnov distribution admits a power series expansion in $n^{-1/2}$ obtained by Euler–Maclaurin app...

taocpmathematicsalgorithmsvolume-1
TAOCP 3.3.1 Exercise 19

A natural multivariate analogue of the Kolmogorov-Smirnov test is obtained by comparing the empirical distribution function F_n(x_1,\ldots,x_s) = \frac1n \#\{\,j: X_{j1}\le x_1,\ldots,X_{js}\le x_s\,\...

taocpmathematicsalgorithmsvolume-1
TAOCP 3.3.1 Exercise 17

Let $t$ be a fixed real number and, for $0 \le k \le n$, define P_{nk}(x) = \int_{-t}^{t} dx_n \int_{-t}^{t} dx_{n-1} \cdots \int_{-t}^{t} dx_{k+1} \int_0^x dx_k \int_0^{x_k} dx_{k-1} \cdots \int_0^{x...

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 3.3.1 Exercise 16

We are asked to generalize Theorem 1.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 3.3.1 Exercise 18

Let each observation in the experiment be an outcome in a finite set $\Omega$, and let $P$ be the probability measure assigning probability $p_s$ to category $s$, with independent observations.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.1 Exercise 14

Let Y_i=np_i+\sqrt{np_i}\,Z_i , where $Z_i$ is defined by Eq.

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 3.3.1 Exercise 15

We compute the Jacobian of the transformation x_k = r\sin\theta_1\cdots\sin\theta_{k-1}\cos\theta_k \quad (1\le k<n), \qquad x_n = r\sin\theta_1\cdots\sin\theta_{n-1}.

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 3.3.1 Exercise 12

**Solution to Exercise 3.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.3.1 Exercise 11

Let the original KS test be based on $n$ observations $X_1,\ldots,X_n$, with empirical distribution function $F_n(x)$.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 3.3.1 Exercise 13

Equations (11) and (13) in Section 3.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.1 Exercise 9

Let the 20 values of $K_{10}^+$ be X_1,\dots,X_{20}, and let the corresponding 20 values of $K_{10}^-$ be

taocpmathematicsalgorithmsvolume-1hard
TAOCP 3.3.1 Exercise 10

Let the original chi-square test be based on a partition of outcomes into categories $1,2,\dots,k$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.3.1 Exercise 6

Let the underlying distribution function be $F(x)$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.1 Exercise 7

In Section 3.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.3.1 Exercise 8

The statistic $K_{10}^{+}$ is computed from blocks of length $10$, but the Kolmogorov-Smirnov test in this exercise is not being applied to the original observations within those blocks.

taocpmathematicsalgorithmsvolume-1
TAOCP 3.3.1 Exercise 4

Let the first die be fair, and let the second die be loaded so that it can show only $1$ or $6$, each with probability $\tfrac12$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.3.1 Exercise 1

The value $V = 7\frac{1}{16}$ corresponds to the chi-square statistic computed from $k = 11$ categories, as in Eq.

taocpmathematicsalgorithmsvolume-1
TAOCP 3.3.1 Exercise 3

**Corrected Solution for Exercise 3.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.3.1 Exercise 2

Let the first die be biased toward the value $1$, and let the second die be biased toward the value $6$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.2.2 Exercise 37

**Solution to Exercise 3.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 3.2.2 Exercise 36

Let f(x)=a x^{-1}+c \pmod{2^e}, with

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.2.2 Exercise 35

Let f(x)=x^2-cx-a over the field $\mathbf F_p$, where $p$ is prime.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 3.2.2 Exercise 33

Stopped thinking

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.2.2 Exercise 32

Let X_n=(X_{n-2}+X_{n-55})\pmod m .

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.2.2 Exercise 30

**Corrected Solution for Exercise 3.

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 3.2.2 Exercise 29

**Exercise 3.

taocpmathematicsalgorithmsvolume-1project
TAOCP 3.2.2 Exercise 28

**Exercise 3.

taocpmathematicsalgorithmsvolume-1project
TAOCP 3.2.2 Exercise 26

Let $(X_n)$ be the sequence defined modulo $p^\lambda$ by X_n=x_n \pmod{p^\lambda}, \qquad 0\le n<k, and

taocpmathematicsalgorithmsvolume-1math-research
TAOCP 3.2.2 Exercise 27

Let $(X_n)$ be a sequence of integers modulo $m$, with period length $\lambda \gg k$, and let Algorithm B act on $(X_n)$ as described in Section 3.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.2.2 Exercise 25

In Program A of Section 3.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 3.2.2 Exercise 24

Let Y_n=(Y_{n-l}+Y_{n-k}) \pmod 2, \qquad 0<l<k, and suppose that every nonzero sequence satisfying this recurrence has period

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.2.2 Exercise 21

Let S=(\mathbb Z_m)^k and write a state as

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.2.2 Exercise 23

The recurrence is X_n=(X_{n-31}-X_{n-24})\pmod m.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.2.2 Exercise 22

Let $m = p_1 p_2 \cdots p_s$, where $p_1,\ldots,p_s$ are distinct primes.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.2.2 Exercise 19

We restart from the correct criterion and remove the unsupported construction.

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 3.2.2 Exercise 20

Method (10) of Section 3.

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 3.2.2 Exercise 16

Let the binary representation of $\mathrm{CONTENTS}(A_n)$ be \mathrm{CONTENTS}(A_n) = (c_{n,1} c_{n,2} \ldots c_{n,k})_2, where $c_{n,i} \in {0,1}$ for $1 \le i \le k$, and $c_{n,1}$ is the most signi...

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.2.2 Exercise 18

Let $X_n$ be the binary sequence generated by method (10) with $k=35$ and CONTENTS$(A)=(a_1a_2\ldots a_{35})_2$, where $a_{35}=1,\quad a_{31}=a_{33}=a_{35}=1,\quad a_i=0 \text{ otherwise in the final...

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.2.2 Exercise 17

Let $m, k \in \mathbb{Z}^+$, and define the sequence $(X_n)$ by X_1 = X_2 = \cdots = X_k = 0, and, for $n \ge 1$,

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.2.2 Exercise 15

The previous solution fails because it never constructs a valid global structure linking the return-time function $q_n$ with the indexing of the base period of $X_n$, and it incorrectly treats periodi...

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.2.2 Exercise 14

Let $(X_n)$ and $(Y_n)$ be integer sequences modulo $m$, with periods $\lambda_1$ and $\lambda_2$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.2.2 Exercise 13

Let $(X_n)$ and $(Y_n)$ be sequences of integers modulo $m$ with periods $\lambda_1$ and $\lambda_2$, respectively.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.2.2 Exercise 12

The sequence is defined modulo $2^e$ by $X_{n+1} = aX_n + bX_{n-1} + c \pmod{2^e}, \qquad n \ge 1.$ The goal is to choose integers $a,b,c,X_0,X_1$ so that the resulting sequence has maximal possible p...

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.2.2 Exercise 10

Let X_{n+1}=X_n+X_{n-1}\pmod{2^e} and write the state vector

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.2.2 Exercise 8

Let $m = 2^e$ and consider the modified middle-square sequence defined by Coveyou: $X_0 \text{ given}, \qquad X_{n+1} = \operatorname{middle}(X_n^2 + 2^{e-1} X_n), \eqno(4)$ where the function $\opera...

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 3.2.2 Exercise 11

Let $R_{p^r} = (\mathbb{Z}/p^r\mathbb{Z})[z]/(f(z))$ with $f(0)=1$, and denote by $\overline{z}$ the residue class of $z$ in $R_{p^r}$.

taocpmathematicsalgorithmsvolume-1math-project