brain

tamnd's digital brain — notes, problems, research

41246 notes

TAOCP 3.3.1 Exercise 5

Let $x_1,\dots,x_{20}$ denote the observations, and let $x_{(1)} \le \cdots \le x_{(20)}$ be the ordered sample.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 4.7 Exercise 17

Let $V(z)=\sum_{m\ge1} V_m z^m,$ and define $v_{nk}=\frac{1}{n}[z^k]V(z)^n,\qquad V_n(x)=\sum_{k=0}^n v_{nk}x^k.$ From the multinomial expansion of a power series,

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.1 Exercise 22

Let $f$ be a random function on a (typically infinite) set, meaning that for each input $x$, the value $f(x)$ is chosen according to a fixed distribution on outputs, and the random variables $\{f(x)\}...

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.4.2 Exercise 17

Let $S_j$ denote the set after the $j$th iteration of the algorithm, where $j$ runs from $N-n+1$ to $N$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.5.2 Exercise 35

The solution does not correctly answer the problem.

taocpmathematicsalgorithmsvolume-1math-medium
CF 104614I - Road To Savings

The city is modeled as an undirected weighted graph. Each intersection is a vertex and each road is an edge whose weight is its length.

codeforcescompetitive-programming
TAOCP 3.3.3 Exercise 2

The function $((x))$ is $1$-periodic and defined on $0 \le x < 1$ by $((x)) = x - \frac12,$ since $\lfloor x \rfloor = 0$ and $\lceil x \rceil = 1$ for $0 < x < 1$ in (7).

taocpmathematicsalgorithmsvolume-1hm-medium
TAOCP 4.6.1 Exercise 22

Let $f_0=f,\ f_1=f',\ f_{i+1}=-\operatorname{rem}(f_{i-1},f_i)$ be the Sturm sequence, and let the process terminate with a nonzero constant $f_s$.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.6.1 Exercise 18

A correct solution must repair three fundamental issues in the previous attempt: 1.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.4.1 Exercise 27

Let a subroutine be available that returns independent random bits $B \in {0,1}$ with $\Pr{B=1}=\Pr{B=0}=\tfrac12$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 3.4.1 Exercise 14

Let $X$ have continuous distribution function $F(x)=\Pr{X\le x}$ and define $Y=cX$, where $c$ is a constant.

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 4.3.1 Exercise 33

Let $u = (u_{n-1}\ldots u_1u_0)_b$.

taocpmathematicsalgorithmsvolume-1
TAOCP 4.3.1 Exercise 4

Let $U = (u_{n-1}\ldots u_0)_b,\quad V = (v_{n-1}\ldots v_0)_b,\quad W = (w_{n-1}\ldots w_0)_b.$ Define for each $j$ with $0 \le j \le n$ the partial values $U_j = \sum_{i=0}^{j-1} u_i b^i,\quad V_j =...

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 3.2.2 Exercise 34

Let $p$ be prime and let f(x)=x^{2}-cx-a\in\mathbb{F}_{p}[x],\qquad R=\mathbb{F}_{p}[x]/(f).

taocpmathematicsalgorithmsvolume-1math-medium
CF 104614H - Picking Up Steam

We are given a terrain described by a polyline that is monotone in x, so it is a chain of straight segments from left to right. A camera sits at a fixed point on this terrain, at a specified x-coordinate, meaning its y-coordinate is determined by the terrain at that x.

codeforcescompetitive-programming
CF 104614G - Pea Pattern

We are given two very large integers written as digit strings. The first number is used as the starting point of a deterministic sequence, and the second number is the target we are trying to locate inside that sequence. The sequence evolves in a very specific way.

codeforcescompetitive-programming
CF 104614F - It's About Time

We are asked to design a simplified “leap-year system” for a fictional planet whose year length is not exactly an integer number of local days. From physics, the input gives enough information to compute how long the planet takes to complete one orbit around its star.

codeforcescompetitive-programming
CF 104614E - Hilbert's Hedge Maze

The maze is not given explicitly. Instead, it is generated by repeatedly expanding a symbolic string that behaves like a growing fractal instruction system.

codeforcescompetitive-programming
CF 104614A - A-Mazing Puzzle

We are given a rectangular maze and two robots placed on different cells with initial directions. The maze is a grid where movement is blocked by internal walls and the outer boundary, except for a single exit located on the southern border of one specific cell.

codeforcescompetitive-programming
CF 104614C - Cribbage On Steroids

We are given a multiset of cards, each card described only by its rank. Suits do not matter. The task is to compute a single score based on three independent scoring rules applied over the entire collection, not just five cards.

codeforcescompetitive-programming
TAOCP 3.2.2 Exercise 31

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

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.2.2 Exercise 4

In MIX arithmetic each word consists of several bytes, and operations such as multiplication and addition propagate carries from less significant positions toward more significant positions.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 3.5 Exercise 31

Let ${U_n}_{n \ge 0}$ be a binary sequence, so each $U_n \in {0,1}$.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 3.5 Exercise 30

Let $(Y_n)_{n\ge 1}$ be an i.

taocpmathematicsalgorithmsvolume-1math-project
TAOCP 3.5 Exercise 21

Let $U_0, U_1, \ldots$ be a $[0,..,1)$ sequence with $U_0 = 0$.

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 4.5.3 Exercise 40

We fix the construction precisely before proving any properties.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.3 Exercise 33

Define f_0(z)=\tanh z=\frac{e^z-e^{-z}}{e^z+e^{-z}},\qquad f_{n+1}(z)=\frac{1}{f_n(z)}-\frac{2n+1}{z}.

taocpmathematicsalgorithmsvolume-1math-hard
TAOCP 4.5.3 Exercise 16

Let f_0(z)=\tanh z=\frac{e^z-e^{-z}}{e^z+e^{-z}}, \qquad f_{n+1}(z)=\frac{1}{f_n(z)}-\frac{2n+1}{z}.

taocpmathematicsalgorithmsvolume-1hm-hard
TAOCP 2.4 Exercise 6

The proposed solution captures the high-level idea of PL/I qualification: each item is identified by its full chain of ancestors, and ambiguity is resolved by complete qualification.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.4.1 Exercise 12

The algorithm in Exercise 11 is Prim’s construction of a minimum-cost spanning tree, but it is stated in a form that repeatedly renumbers vertices and updates an entire cost matrix.

taocpmathematicsalgorithmsvolume-1
CF 104614B - A Musical Question

We are given a fixed capacity for two identical CDs and a list of song durations. Each CD can hold at most c minutes of music, and every song can be placed on at most one CD or skipped entirely.

codeforcescompetitive-programming
TAOCP 1.4.3.1 Exercise 7

The reviewer’s objection targets a genuine modeling mistake in the explanation: not the timing formula itself, but the _interpretation of device occupancy during the delay interval_.

taocpmathematicsalgorithmsvolume-1hard
CF 104617D - Ice Cream Lasagna

We are given a sequence of $n$ layers, and each layer contains a string made of characters $R$ and $G$. Each character represents a candy of a specific color, and the string represents the order in which candies appear inside that layer from top to bottom.

codeforcescompetitive-programming
TAOCP 1.4.3.1 Exercise 3

Let $M$ and $F$ denote the address and field of the instruction, already placed in $rI5$ and $rI3$ by the control routine, and let $X$ denote the index register contents stored in $XREG$.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.3.1 Exercise 1

Let the field specification byte be denoted by $x = \mathrm{INST}(4:4)$.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.2.5 Exercise 20

Let $x>0$.

taocpmathematicsalgorithmsvolume-1
TAOCP 1.2.5 Exercise 11

Let $\mu=\sum_{k>0}\left\lfloor \frac{n}{2^k}\right\rfloor$ be the exponent of $2$ in $n!$ by equation (8).

taocpmathematicsalgorithmsvolume-1
TAOCP 1.2.5 Exercise 2

From equation (2), p_{nk} = n(n-1)\cdots(n-k+1).

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.5 Exercise 12

The previous solution failed because it implicitly allowed uncontrolled queue duplication and did not establish a genuine worst-case per-operation bound independent of heap size and history.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.5 Exercise 11

We model a List structure as a finite directed, rooted, ordered graph.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.5 Exercise 9

The key correction is to treat pointer updates as **field updates inside each node** and to separate clearly the logical relabeling of pointers from the physical relocation step.

taocpmathematicsalgorithmsvolume-1
CF 104687C - Сумма 1

We are given two integer intervals: one interval defines all valid values of $x$, and the other defines all valid values of $y$. We also have a target sum $n$.

codeforcescompetitive-programming
TAOCP 2.3.5 Exercise 5

A precise combined Schorr–Waite marking procedure is obtained by running a depth-first traversal in which the stack stores continuation states exactly as in Algorithm B, and the pointer-reversal mecha...

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.5 Exercise 1

A List can be described as a finite directed graph whose vertices correspond to memory nodes and whose directed edges correspond to pointer fields such as `RLINK` and `DLINK`.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.4.5 Exercise 17

Let $T(z)=\sum_{n\ge1} t_n z^n$ be the generating function where $t_n$ counts unlabeled ordered trees with $n$ terminal nodes and no nodes of degree $1$.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.4.5 Exercise 14

We repair the argument by separating three facts that were previously conflated: 1.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.4.5 Exercise 13

Maintain two FIFO queues.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.4.5 Exercise 10

The binary case extends directly.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.4.5 Exercise 8

Let the complete $t$-ary tree have internal nodes ${1,2,\ldots,n}$, and let q=\left\lfloor \log_t((t-1)n+1)\right\rfloor.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.4.5 Exercise 4

We prove the statement by induction on $m$.

taocpmathematicsalgorithmsvolume-1
TAOCP 2.3.4.5 Exercise 2

The construction follows Huffman’s algorithm applied to the weights in nondecreasing order.

taocpmathematicsalgorithmsvolume-1
TAOCP 1.4.4 Exercise 19

Block $k$ starts input at time $t_k$ satisfying t_1 = 0,\qquad t_k \equiv (k-1)L \pmod P,\qquad t_k \text{ increasing in } k.

taocpmathematicsalgorithmsvolume-1math-hard
CF 104617G - Ice Cream Gambling

We are given two independent lists that interact through a single decision: how many customers we serve using available cones. Each customer has a value $ri$, which represents the profit you would obtain if you successfully serve that customer with a chocolate-mint cone.

codeforcescompetitive-programming
CF 104617E - Cone Coloring

We are given a line of colored dyes, each dye having a positive integer value that represents how “beautiful” it is.

codeforcescompetitive-programming
CF 104617B - Ice Cream Biorhythm

We are given five cubic polynomials. Three of them represent the “status” of three ice cream companies over time, and two represent external factors (UV index and heat index). At a specific hour d, we evaluate all five polynomials.

codeforcescompetitive-programming
TAOCP 1.4.4 Exercise 18

The purpose of the interrupt extension is to eliminate the busy waiting performed by `JRED`.

taocpmathematicsalgorithmsvolume-1hard
TAOCP 1.4.4 Exercise 17

The error in the proposed solution stems from an incorrect output discipline and an underspecified buffer-state structure.

taocpmathematicsalgorithmsvolume-1project
TAOCP 1.4.4 Exercise 13

The key point in Knuth’s buffered coroutine design is that termination is expressed purely through the **buffer–handoff protocol**, not through any external flag or global state.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.4 Exercise 11

The original schedule (Fig.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.4 Exercise 9

The solution does not answer the question asked.

taocpmathematicsalgorithmsvolume-1medium
TAOCP 1.4.4 Exercise 8

Section 1.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.4.4 Exercise 6

The subroutine `WORDIN` assumes that a circular pair of buffers is already set up in memory and that index register $6$ always points into the current buffer.

taocpmathematicsalgorithmsvolume-1simple
TAOCP 1.3.3 Exercise 28

Let the Josephus process on $\{1,\dots,n\}$ use the standard convention: starting from a fixed cyclic order, we repeatedly advance $m-1$ steps in the current cycle and delete the next element.

taocpmathematicsalgorithmsvolume-1math-medium
CF 104617H - Cone Factory

We are given several cone molds placed at distinct integer positions on a line. We are allowed to choose exactly one starting position from which a vertical stream of batter begins flowing downward. The factory also contains horizontal spreader segments.

codeforcescompetitive-programming
TAOCP 1.3.3 Exercise 25

Let T(n)=\sum_{k=1}^{n}(k-1)(n-k)!

taocpmathematicsalgorithmsvolume-1math-medium
TAOCP 1.3.3 Exercise 23

Let a permutation of ${1,\dots,n}$ be chosen uniformly from $S_n$.

taocpmathematicsalgorithmsvolume-1hm-project
TAOCP 1.3.3 Exercise 22

We correct the argument by deriving the distribution in part (a) directly from the two stated conditions, without assuming Poisson structure or independence in advance.

taocpmathematicsalgorithmsvolume-1hm-hard
CF 104617F - Bing is Chilling

We are given a collection of named ingredients, each of which can either be bought directly for a fixed price or produced using other ingredients according to a recipe. Some ingredients are final targets that Bing needs in order to make his ice cream flavor.

codeforcescompetitive-programming
CF 104617C - Sweet Selections

We are given three independent collections of strings: ice cream flavors, drizzles, and toppings. A dessert consists of exactly two scoops of ice cream, one drizzle, and one topping.

codeforcescompetitive-programming
CF 104617A - Get to the Choppa!

We are given a collection of ice blocks, each tagged with a flavor name and a number that represents how long that block takes to melt.

codeforcescompetitive-programming
CF 104618J - Starfruit Ice Cream

We are asked to choose exactly $n$ distinct cells in an $n times n$ grid. Each chosen cell is a “pouring point” where a unit of milk is placed.

codeforcescompetitive-programming
TAOCP 1.3.3 Exercise 20

Let a permutation of $n$ elements have exactly $\alpha_j$ cycles of length $j$, for $1 \le j \le n$, including $\alpha_1$ singleton cycles written explicitly.

taocpmathematicsalgorithmsvolume-1math-medium
CF 104618I - Magic Sprinkles

We are given a set of points in the plane, each representing a sprinkle placed somewhere above the x-axis, since all y-coordinates are strictly positive. Each sprinkle has a color, either red or blue.

codeforcescompetitive-programming
CF 104618H - Cone Factory

Each cone mold sits at a distinct integer coordinate on the X-axis. From above, every coordinate has an infinitely high dispenser that can drop batter straight down, but in reality only one dispenser can be activated, so initially we only have one vertical stream starting from…

codeforcescompetitive-programming
CF 104618F - Bing is Chilling

We are given a collection of ingredients where each ingredient has two ways of obtaining it. You can either buy it directly at a fixed price, or you can produce it by combining other ingredients, which themselves may also be bought or produced.

codeforcescompetitive-programming
CF 104618G - Ice Cream Gambling

We are given two independent collections that interact through a trading process. One collection represents customers, each customer $i$ willing to pay $ri$ if they successfully receive chocolate-mint ice cream.

codeforcescompetitive-programming
CF 104618E - Cone Coloring

We are given a line of $N$ dyes, each with a positive integer beauty value. From this sequence we want to choose a subset of positions such that no two chosen positions are adjacent in the original line.

codeforcescompetitive-programming
CF 104618D - Ice Cream Lasagna

We are given a vertical stack of $n$ ice cream layers. Each layer is a string over the alphabet ${R, G}$, representing candies in that layer from left to right. The process is strictly sequential: we start from layer 1, then 2, and so on until layer $n$.

codeforcescompetitive-programming
TAOCP 1.3.3 Exercise 18

Let $S_n$ be the set of all permutations of ${1,2,\dots,n}$, chosen uniformly.

taocpmathematicsalgorithmsvolume-1math-hard
CF 104618C - Sweet Selections

We are given three independent lists of strings: available ice cream flavors, available drizzles, and available toppings. A valid dessert consists of choosing exactly two scoops of ice cream, then choosing one drizzle and one topping.

codeforcescompetitive-programming
CF 104619L - Location, Location, Location

We are given a set of points on a 2D grid, each representing a location such as a house or apartment. We must choose a new point $(x, y)$ where a charging station will be built.

codeforcescompetitive-programming
CF 104619K - Kick

We are given a single long string consisting only of lowercase English letters. The task is to count how many times the pattern “kick” appears as a contiguous substring.

codeforcescompetitive-programming
CF 104619H - Heap Structure

We are given a min-heap containing the values from 1 to n, where n is extremely large, up to 10^18, and we focus on the element with rank k in sorted order, which is simply the value k itself.

codeforcescompetitive-programming
CF 104619I - Introversion

We are given a linear table of length $2n$. Each position either already contains a dish of type $1 dots n$ or is empty. Every type appears at most twice in the initial configuration, and whenever it appears twice those two occurrences are not adjacent.

codeforcescompetitive-programming
TAOCP 1.3.3 Exercise 16

Let $T$ be the operation described: 1.

taocpmathematicsalgorithmsvolume-1math-simple
CF 104619J - Java Warriors

We are given a single integer $n$ representing how many ICPC teams Jerry is sending to a contest. Each team requires a fixed registration fee of 4000 dollars. The task is to compute the total amount of money needed to register all teams.

codeforcescompetitive-programming
CF 104619G - Gadget Construction

Codeforces 104619G: Gadget Construction

codeforcescompetitive-programming
CF 104619E - Exponentiation

We are given a positive integer α that is defined as the sum of a number x and its reciprocal 1/x. In other words, x is some (possibly complex) number satisfying x + 1/x = α. From this implicit definition, we are asked to compute the value of x^β + (1/x)^β modulo m.

codeforcescompetitive-programming
CF 104619C - Cutting into Monotone Increasing Sequence

We are given a very long integer written as a string of digits, and we are allowed to insert commas between digits to split it into contiguous chunks. Each chunk is interpreted as a number.

codeforcescompetitive-programming
CF 104619F - Finding Bridges

We are given an undirected simple graph and a sequence of edge deletions. After each deletion, we must report how many bridges remain in the current graph.

codeforcescompetitive-programming
CF 104619D - Divide a Convex

We are given a convex polygon with up to 100000 vertices in order. We must choose two points P and Q, each lying on different edges of the polygon, and draw a segment PQ inside the polygon. This segment splits the polygon into two convex polygons.

codeforcescompetitive-programming
CF 104619B - Better Chance

We are given two independent regional contests, Taoyuan and Jakarta. For each contest, we know two quantities: the recomputed rank of our team inside that contest and a “site score” that summarizes the overall strength and scale of that contest.

codeforcescompetitive-programming
CF 104619A - Advance to Taoyuan Regional

We are given a single calendar date in the year 2023, written as YYYY-MM-DD. This date represents when a programming contest (TOPC) is planned to be held.

codeforcescompetitive-programming
CF 104627D - Clock Gallery

We are given a collection of 24-hour clocks, each showing a precise time down to seconds. Separately, we are told a list of cities, and for each city we know how many seconds ahead or behind Paris it is.

codeforcescompetitive-programming
CF 104627E - Coin Puzzle

I can’t reliably write a correct editorial for this problem yet because the actual problem statement for Codeforces 104627E - Coin Puzzle isn’t included in your prompt.

codeforcescompetitive-programming
CF 104627B - Connect

We are given an $n times n$ grid that starts empty, and two players alternately drop tokens into columns. Each move chooses a column, and the token falls to the lowest available cell in that column, like gravity in Connect Four.

codeforcescompetitive-programming
CF 104627A - Forgery

We are given a grid of characters that represents a sheet of paper, where each cell is either empty or marked. The task is to determine whether the pattern of marked cells could have been produced by a single rectangular stamp that was pressed one or more times onto an…

codeforcescompetitive-programming
TAOCP 1.3.3 Exercise 15

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

taocpmathematicsalgorithmsvolume-1math-simple
CF 104627C - Reading Numbers

I can write the full editorial in the exact style you requested, but I need the actual problem statement (or at least a link or summary of the task).

codeforcescompetitive-programming
CF 104630B - Overrandomized

Each test case describes a single hidden permutation of the digits 0 through 9 into uppercase letters. In other words, every digit is represented by exactly one letter, and every letter represents exactly one digit. The server encodes numbers using this unknown substitution.

codeforcescompetitive-programming