brain

tamnd's digital brain — notes, problems, research

43815 notes

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 18

**Exercise 3.

taocpmathematicsalgorithmsvolume-1math-medium
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 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 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 14

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

taocpmathematicsalgorithmsvolume-1math-simple
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 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
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 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 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 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 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 16

We are asked to generalize Theorem 1.

taocpmathematicsalgorithmsvolume-1hm-hard
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 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 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 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 6

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

taocpmathematicsalgorithmsvolume-1math-medium
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 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.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.2.2 Exercise 36

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

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.2.2 Exercise 37

**Solution to Exercise 3.

taocpmathematicsalgorithmsvolume-1hm-hard
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 29

**Exercise 3.

taocpmathematicsalgorithmsvolume-1project
TAOCP 3.2.2 Exercise 30

**Corrected Solution for Exercise 3.

taocpmathematicsalgorithmsvolume-1math-project
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 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 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 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 21

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

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.2.2 Exercise 20

Method (10) of Section 3.

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

Let the MIX machine have accumulator $A$, index register $X$, and overflow toggle $O$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.2.2 Exercise 6

Let the binary method (10) be the scheme in which a word $X$ is updated by shifting and inserting a random bit, so that each step effectively appends a new random least significant bit while discardin...

taocpmathematicsalgorithmsvolume-1simple
TAOCP 3.2.2 Exercise 3

Work modulo $8$ throughout.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.2.2 Exercise 5

**Corrected Solution to Exercise 3.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.2.2 Exercise 2

From the Fibonacci generator, X_{n+1} = (X_n + X_{n-1}) \bmod m, there exists an integer $t \in {0,1}$ such that

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.2.2 Exercise 1

We consider the linear congruential generator (LCG) in its standard integer form: X_{n+1} = (a X_n + c) \bmod m, \quad X_0 \in \{0,1,\dots,m-1\}.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 3.2.1.3 Exercise 7

Since \(a\) satisfies the conditions of Theorem 3.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.2.1.3 Exercise 8

The generator is X_{n+1}\equiv aX_n \pmod{2^{35}}, \qquad a=2^{17}+3, \qquad

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.2.1.3 Exercise 6

By Exercise 5, if m=p_1^{e_1}\cdots p_r^{e_r}, \qquad a=1+k\,p_1^{f_1}\cdots p_r^{f_r},

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.2.1.3 Exercise 5

Let m=p_1^{e_1}p_2^{e_2}\cdots p_r^{e_r}, and let

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.2.1.3 Exercise 4

Let $m = 2^e$ with $e \ge 3$.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 3.2.1.3 Exercise 3

We consider the multiplicative linear congruential sequence modulo $m = 2^{35}$, so we study the multiplicative order of $a$ in the unit group $(\mathbb{Z}/2^{35}\mathbb{Z})^\times$.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 3.2.1.3 Exercise 2

In (3) the multiplier is $a=B^2+1$, hence $b=a-1=B^2$.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 3.2.1.3 Exercise 1

Let $B$ be the byte size of MIX, so that $m = B^e$ is the word size.

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 3.2.1.2 Exercise 14

Assume $e>1$ and that $a$ is a primitive element modulo $p$.

taocpmathematicsalgorithmsvolume-1math-simple
TAOCP 3.2.1.2 Exercise 12

Let $p$ be an odd prime and let $e>1$.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.2.1.2 Exercise 11

Let $x$ be an odd integer with $x>1$.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.2.1.2 Exercise 9

**Corrected Solution for Exercise 3.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.2.1.2 Exercise 10

Write m=2^{e}p_1^{e_1}\cdots p_t^{e_t}, where $p_1,\dots,p_t$ are distinct odd primes.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.2.1.2 Exercise 7

Let the modulus be m = p_1^{e_1} p_2^{e_2} \cdots p_t^{e_t}, and let $(X_n)$ denote the linear congruential sequence defined by $(X_0, a, c, m)$:

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.2.1.2 Exercise 6

By Theorem A, the multipliers that yield the maximum period are characterized by the conditions a-1 \equiv 0 \pmod p for every prime divisor $p$ of $m$, together with the additional condition

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.2.1.2 Exercise 8

We are asked to show that if a \equiv 3 \pmod 4, then, for every integer $e>1$,

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.2.1.2 Exercise 5

We are asked to find all multipliers $a$ satisfying the conditions of Theorem A when $m = 2^{35} + 1$.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 3.2.1.2 Exercise 4

Let $m = 2^e$, and let $(X_n)$ be the linear congruential sequence defined by $X_{n+1} \equiv a X_n + c \pmod{2^e}, \qquad X_0 = 0,$ where $a$ and $c$ satisfy the conditions of Theorem A.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.2.1.2 Exercise 3

Let $m = 10^e$ with $e \ge 2$, and let $c$ be odd and not a multiple of 5.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 3.2.1.2 Exercise 2

Let \(x_{n+1} \equiv a x_n + c \pmod{m}\) with \(m = 2^k\), and consider the conditions \[ c \text{ is odd}, \qquad a \equiv 1 \pmod{4}.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.2.1.1 Exercise 13

We are asked to perform computations modulo $m = 9999999001$, with multipliers $a = 10$ and $a = 9999999101$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.2.1.1 Exercise 14

**Exercise 3.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.2.1.2 Exercise 1

We first verify the conditions of Theorem A for the given parameters.

taocpmathematicsalgorithmsvolume-1simple