brain

tamnd's digital brain — notes, problems, research

41641 notes

TAOCP 7.1.4 Exercise 11

Algorithm C in Section 7.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.4 Exercise 109

Let the current composition of $n$ be s_1 s_2 \cdots s_j, and let

taocpmathematicsalgorithmsvolume-4hm-medium
TAOCP 7.1.4 Exercise 108

The solution does not correctly establish the required inequality.

taocpmathematicsalgorithmsvolume-4hm-medium
TAOCP 7.1.4 Exercise 107

Let $f(x_1,\dots,x_n)$ be a Boolean function represented by a reduced ordered BDD, and let $B(f)$ denote its number of nodes including sinks, as defined in Section 7.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.1.4 Exercise 106

Let variables of $f$ be $x_1,\dots,x_n$, variables of $g$ be $y_1,\dots,y_n$, and variables of $h$ be $z_1,\dots,z_n$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.4 Exercise 105

A Boolean function $f(x_1,\dots,x_n)$ is unate with polarities $(y_1,\dots,y_n)$ when the function $h(x_1,\dots,x_n)=f(x_1\oplus y_1,\dots,x_n\oplus y_n)$ is monotone increasing in each variable, mean...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.4 Exercise 104

Let $f$ and $g$ be Boolean functions represented by reduced ordered binary decision diagrams with sink nodes $\bot,\top$ and with variable ordering $x_1 < \cdots < x_n$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.4 Exercise 103

Let \Phi(x_1,\dots,x_n) = \exists y_1 \dots \exists y_m \Bigl(

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.4 Exercise 102

Let $f(x_1,\dots,x_n)$ be a Boolean function represented by its BDD as in Section 7.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.4 Exercise 101

Let $\Sigma_m={0,1,\dots,m-1}$ be the ordered alphabet used for $m$-ary strings in Section 7.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.4 Exercise 100

Let $G=(V,E)$ be the planar adjacency graph of the contiguous United States after eliminating DC, as specified in the exercise.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.4 Exercise 10

Let $f$ and $f'$ be Boolean functions represented by reduced ordered BDDs.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.4 Exercise 9

Let the BDD of $f(x_1,\ldots,x_n)$ be given in the sequential form of (8), with nodes $k_j$ labeled by $V(k_j)=x_j$, LO successor $\operatorname{LO}(k_j)$, HI successor $\operatorname{HI}(k_j)$, and s...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.4 Exercise 8

Let $f(x_1,\ldots,x_n)$ be given and let g_k(x_1,\ldots,x_n)=f(x_1,\ldots,x_{k-2},\,x_{k-1}\oplus x_k,\,x_{k+1},\ldots,x_n).

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.4 Exercise 7

Let $f(x_1,\ldots,x_n)$ be represented by its reduced ordered BDD under variable order $x_1<\cdots<x_n$, and define $g_k(x_0,x_1,\ldots,x_n)=f(x_1',\ldots,x_n')$ where For truth tables, each entry of...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.4 Exercise 6

The truth table of $g(x_1,x_2,x_3,x_4)=f(x_4,x_3,x_2,x_1)$ is obtained by reversing the bit indices of the truth table of $f$.

taocpmathematicsalgorithmsvolume-4simple
TAOCP 7.1.4 Exercise 5

Let $G$ be the BDD of $f(x_1,\dots,x_n)$, and construct a transformed directed acyclic graph $G'$ by interchanging the LO and HI pointers of every branch node and swapping the two sinks $\bot \leftrig...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.4 Exercise 4

Let the 64-bit word $x$ contain fields V \mid LO \mid HI with $V$ occupying the highest 8 bits and each of $LO, HI$ occupying 28 bits.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.4 Exercise 3

Let $f(x_1,x_2,\dots,x_n)$ be a Boolean function and let its BDD size $B(f)$ be the number of nodes in its reduced ordered BDD, including the sinks $\bot,\top$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.4 Exercise 2

Let $F$ be the set of all Boolean functions $f(x_1,x_2)$, represented by their truth tables f = (f(0,0), f(0,1), f(1,0), f(1,1)) \in \{0,1\}^4, so $|F| = 16$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.4 Exercise 1

A BDD is an ordered reduced directed acyclic graph with variable ordering $x_1 < x_2$, sinks $\bot,\top$, and branch nodes labeled by variables.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 99

All operations act on octabytes bytewise, so the computation reduces to a single 8-bit word.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.1.3 Exercise 98

Each byte $x_j$ and $y_j$ is interpreted as an unsigned 8-bit integer in ${0,\ldots,255}$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 97

The proposed solution does not address the problem stated in Exercise 7.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 96

For (93), the addition identity in (8q) has the form $x + y = (x \oplus y) + 2(x \,\&\, y).$ The subtraction analogue is obtained by replacing addition with subtraction and replacing carry propagation...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 95

Let $\mu = (11111111)_{256}$, the word whose every byte equals $255$, so $\mu$ serves as a mask selecting all byte positions.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 94

The operation defined in (qo) constructs each byte $t_j$ from the bytes of $x$ using only bytewise arithmetic and bitwise propagation between neighboring bytes.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 93

Formula (8q) for addition states the bitwise decomposition $x + y = (x \oplus y) + 2(x \mathbin{\&} y).$ To obtain the subtraction analogue, write $x - y = x + (-y).$ Using $,-y = \bar{y} + 1,$ from (...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 92

Represent the 32 base-$4$ digits packed into a word as two-bit fields.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 91

Represent the 32 base-$4$ digits packed into a word as two-bit fields.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.1.3 Exercise 90

Represent the 32 base-$4$ digits packed into a word as two-bit fields.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 89

The solution does not address the stated problem at all.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 88

The solution does not correctly resolve the optimization problem.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 87

The solution does not correctly resolve the optimization problem.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 86

Let the array indices satisfy \[ 0 \le i < 2^p,\quad 0 \le j < 2^q,\quad 0 \le k < 2^r, \] with binary expansions \[

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.1.3 Exercise 85

Let $i=(i_4 i_3 i_2 i_1 i_0)_2$, $j=(j_4 j_3 j_2 j_1 j_0)_2$, $k=(k_4 k_3 k_2 k_1 k_0)_2$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 84

Let $\chi$ contain exactly $2^d$ one-bits and let these bits occur at positions \chi = \sum_{j=0}^{2^d-1} 2^{p_j}, \qquad p_0 < p_1 < \cdots < p_{2^d-1}.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 83

Let $\chi$ be a mask with exactly $2^d$ one-bits.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.1.3 Exercise 82

Let $\chi$ be a fixed set of nonnegative integers closed under the relation $x \subseteq \chi$, meaning every 1-bit position of $x$ corresponds to an element of $\chi$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 81

Let $\chi$ be a fixed set of nonnegative integers closed under the relation $x \subseteq \chi$, meaning every 1-bit position of $x$ corresponds to an element of $\chi$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 80

The solution does not address Exercise 7.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 79

The solution does not address Exercise 7.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 78

Each $x_j$ is a nonnegative integer with $x_j < 2^{n-k}$, hence each $x_j$ occupies at most the lowest $n-k$ bits.

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.1.3 Exercise 77

A mapping network on $n$ inputs uses $2\times 2$ modules, each module taking inputs $(a,b)$ and producing one of $(a,b)$, $(b,a)$, $(a,a)$, $(b,b)$.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.1.3 Exercise 76

A mapping network on $n$ inputs uses $2\times 2$ modules, each module taking inputs $(a,b)$ and producing one of $(a,b)$, $(b,a)$, $(a,a)$, $(b,b)$.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.1.3 Exercise 75

The solution targets the correct object: the cyclically shifted counts and the balance condition \sum c'_{2t}=\sum c'_{2t+1}.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.1.3 Exercise 74

The solution targets the correct object: the cyclically shifted counts and the balance condition \sum c'_{2t}=\sum c'_{2t+1}.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 73

Let the $2^d$ bit positions be indexed by binary vectors $u = (u_{d-1}\ldots u_0)_2 \in {0,1}^d$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 72

Let the word size be $2^k$ bits, with bit positions indexed $0,1,\ldots,2^k-1$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 71

Let $\theta_0,\theta_1,\ldots,\theta_{d-1}$ be the masks used in compression procedure (80).

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 70

The solution does not correctly address what Steele’s problem is asking in the context of method (80).

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.1.3 Exercise 69

The δ-shift operation (79) is the packed word transformation that produces a result $v$ from an input $u$ by forming a shifted copy of $u$ and combining it with $u$ by bitwise exclusive-or.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 68

The δ-shift operation (79) is the packed transformation on a word $u$ that shifts selected bit blocks by $\delta$ positions and combines results by XOR.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 44

Let $x = \sum_{j \ge 0} x_j 2^j$ with $x_j \in {0,1}$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 43

Let $w$ denote the word length of MMIX.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 42

Let $u = 2^{e_1} + \cdots + 2^{e_r}$ with $e_1 > \cdots > e_r \ge 0$.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.1.3 Exercise 33

Let $y = 2^j + 2^k$ with $64 > j > k \ge 0$.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.1.3 Exercise 25

Each volume consists of 250 sheets of thickness $0.1\ \text{mm}$ each, so the total paper thickness per book is 250 \cdot 0.

taocpmathematicsalgorithmsvolume-4simple
TAOCP 7.1.3 Exercise 24

The failure is fundamental: all control flow in the proposed program is broken because it writes comparison results into register $0$, which is architecturally constant zero in MMIX and cannot be assi...

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.1.3 Exercise 23

Encode “(” as $0$ and “)” as $1$.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.1.3 Exercise 207

The reviewer is correct that the previous solution failed at the logical foundation: it _asserted_ multiplication by $21$ without deriving it from the shuffle.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 206

Let the input word $z$ be split into two halves $x$ and $y$, each consisting of 32 bits, so that $z = (x,y)$ in concatenated form.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 202

The previous solution fails for a structural reason: it replaces the required _wydewise predicate_ w \mapsto [w\neq 0]\cdot \#ffff with bytewise reasoning and then assumes a non-existent “merge-to-wyd...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.1 Exercise 129

Let $C_n$ denote the number of canalizing Boolean functions on $\{0,1\}^n$.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104380F - Double-Ended Queue

We are given a sequence of numbers that must be inserted one by one into a deque. Each number can be placed either at the front or at the back, and once placed, its position is fixed.

codeforcescompetitive-programming
CF 104380D - Primewords Revisit

We are constructing a digit string of length $n$, where each position can independently take a value from 0 to 9.

codeforcescompetitive-programming
CF 104380C - Number Machine

We start with a machine that stores a single integer, initially equal to 1. Two operations are allowed. One operation multiplies the current value by 3 and then adds 2, and the other operation simply increases the value by 1.

codeforcescompetitive-programming
CF 104380A - 01 (Easy Version)

We are given a binary string consisting only of characters 0 and 1. We are allowed to repeatedly find any adjacent pattern "01" and remove it completely from the string, closing the gap left by the deletion.

codeforcescompetitive-programming
CF 104381N - Hopscotch

This is no longer a parsing or I/O issue. The program runs and produces a value (29), but it is mathematically wrong. Let’s trace what the structure of the input implies: The first line strongly suggests: - N = 2, M = 3 Then we have multiple rows of paired data.

codeforcescompetitive-programming
CF 104381M - Friendship

We are given a line of people indexed from 1 to n. Each person i defines a range of other people they “know” based on their position: they know everyone whose index lies between i minus ai and i plus bi, inclusive.

codeforcescompetitive-programming
CF 104381L - Walking to School

We are given a directed or undirected graph of crossings connected by paths. Each path has a snow depth value, and Michael starts at crossing 1 and wants to reach a target crossing T. The twist is that his walking cost is not additive in the usual sense.

codeforcescompetitive-programming
CF 104381G - Anti-Gravity Boots

The failure here is not coming from the mathematical idea, but from execution flow. For the input: the correct output is 5, which matches the standard “count ordered pairs (i, j) where a[i] is divisible by a[j]”.

codeforcescompetitive-programming
CF 104381K - Hopscotch (Easy Version)

We are given two parallel rows of numbered tiles, each row containing $n$ positions. At every index $i$, the left row has a value $ai$ and the right row has a value $bi$.

codeforcescompetitive-programming
CF 104381J - Rash Cloyale

We are given two equal-sized groups of players, each containing $n$ people. Every player has a rating. The organizers will split players into two fixed groups A and B, but the pairing is flexible: each person in A must be matched with exactly one person in B, forming $n$ 2v2…

codeforcescompetitive-programming
CF 104381I - Line up

We are given a sequence of length $n$, and we want to decide whether it could have been produced from some hidden permutation of $1$ to $n$.

codeforcescompetitive-programming
CF 104381H - Grocery Shopping

We are asked to find the smallest integer that Michael can pay such that it is at least a given value $N$, but with a digit constraint on the payment itself. The constraint is purely about the decimal representation of the number we choose.

codeforcescompetitive-programming
CF 104381F - Hello World!

We are given a small array of integers, and we want to count how many ordered triples of indices $(x, y, z)$ satisfy the condition that the product of the two chosen elements equals a third element in the array.

codeforcescompetitive-programming
CF 104381E - Password Guessing

We are tracking a randomized password system that evolves week by week. There is a fixed list of $n+1$ distinct passwords. At the start, in week 1, the system uses the first password in the list. Each week, the password either stays the same or changes.

codeforcescompetitive-programming
CF 104381C - Bashy Math

We are given a collection of integers and we want to count ordered relationships between indices based on divisibility. For every pair of positions $i$ and $j$, we check whether the value at $i$ is divisible by the value at $j$, while ensuring the two indices are different.

codeforcescompetitive-programming
CF 104381D - Star Trek Wall

We are given a small set of axis-aligned rectangular posters placed on a fixed 20 by 20 grid that represents a wall. Each poster covers every cell inside its rectangle, and multiple posters may overlap.

codeforcescompetitive-programming
CF 104381A - Battleship

We are given a square game board of size $n times n$, where each cell is either ocean or a ship. A single query is made: a pair of coordinates $(r, c)$ representing a guessed cell on this board. The task is to determine what exists at that exact position.

codeforcescompetitive-programming
CF 104381B - Knishop

We are given two points on an infinite grid with integer coordinates. A piece starts at the first point and needs to reach the second point. In one move, the piece can behave in two different ways.

codeforcescompetitive-programming
CF 104385K - Split

We are given a sequence that starts out sorted in non-increasing order. The sequence is dynamic, because we are allowed to perform point updates of a very specific form, and we must also answer queries about how best to split the array into contiguous segments.

codeforcescompetitive-programming
CF 104385L - Zhang Fei Threading Needles - Thick with Fine

We are given a single integer $N$, representing the number of soldiers in Cao Cao’s army positioned in front of Changban Bridge. The story describes Zhang Fei’s roar causing panic and making soldiers flee.

codeforcescompetitive-programming
CF 104385H - Permutation

The crash happens before any algorithm runs: Your program is assuming a multi-line format with three integers in the first line, but the actual input is: So: - First line contains only N - Second line contains the array - There are no M, Q, or query lines at all This is not a…

codeforcescompetitive-programming
CF 104385J - Function

We are maintaining a dynamic collection of quadratic functions, all sharing the same shape but shifted along the x-axis and vertically offset. Each function looks like a parabola with fixed curvature 1, centered at some integer position, and then shifted up by a constant value.

codeforcescompetitive-programming
CF 104385I - Tree

We are given a tree where each edge carries an integer value. The tree is fixed, but the edge values change over time. The system supports two operations.

codeforcescompetitive-programming
CF 104385F - Cities

We are given a line of cities labeled from 1 to n, each placed at a distinct coordinate on a number line. Adjacent cities are connected by a road, so initially the graph is just a chain.

codeforcescompetitive-programming
CF 104385G - Copy and Paste

We are given a target lowercase string and an initially empty workspace. The goal is to construct the string using the fewest possible operations under a very specific toolset: we can append a single character to the end of the current text, we can copy the entire current text…

codeforcescompetitive-programming
CF 104385B - Wonderful Array

The crash happens before any algorithm runs: Your program is assuming a multi-line format with three integers in the first line, but the actual input is: So: - First line contains only N - Second line contains the array - There are no M, Q, or query lines at all This is not a…

codeforcescompetitive-programming
CF 104385E - Segment-tree

We are given a complete segment tree over the range from 0 to 2^n − 1. Instead of working with the array directly, the problem constructs an induced graph G by running a segment tree query procedure on an interval [L, R].

codeforcescompetitive-programming
CF 104385D - Stack Out

We are generating sequences of operations on a stack that processes the numbers from 1 to n in increasing order. At any moment, we either take the next unused number and push it onto the stack, or we pop the current top of the stack if it is not empty.

codeforcescompetitive-programming
CF 104385C - Battle

We are given several piles of stones. Two players take turns, and on each turn a player selects exactly one pile and removes a number of stones from it.

codeforcescompetitive-programming
CF 104385A - Drill Wood to Make Fire

We are given a very small simulation repeated multiple times. Each test case describes a scenario where a person is trying to generate fire by drilling wood.

codeforcescompetitive-programming
CF 104386G - CLC Loves SQRT Technology (Hard Version)

We are given an array and we look at every possible non-empty subsequence of it. For each subsequence, we want to know the minimum number of elements we must overwrite so that the subsequence can be turned into a palindrome.

codeforcescompetitive-programming
CF 104386F - CLC Loves SQRT Technology (Easy Version)

We are given a sequence of numbers, and we look at every possible non-empty subsequence. For each chosen subsequence, we are allowed to perform an operation where we pick any element in it and overwrite its value arbitrarily.

codeforcescompetitive-programming
CF 104386B - Random Array

We want the k-th smallest element in a multiset formed by: - X: values xi each repeated si times - Y: values transformed per query as alpha yj + beta, each repeated tj times We never expand arrays. Instead, we answer: how many elements are ≤ v?

codeforcescompetitive-programming
CF 104386D - Comic Numbers

We are asked to count integers inside many large intervals that satisfy a specific divisibility rule tied to their cube root. For any positive integer $x$, we compute $k = lfloor sqrt[3]{x} rfloor$, and we call $x$ valid if it is divisible by $k$.

codeforcescompetitive-programming
CF 104386E - Gridy

We are given a rectangular grid where each cell already contains either a fixed 0, a fixed 1, or an unknown ?. Every unknown cell will later be independently replaced by either 0 or 1, each choice having equal probability.

codeforcescompetitive-programming
CF 104386A - Dungeon videogame

We are given several independent dungeon runs. Each run consists of a sequence of levels, and at each level we must make exactly one choice: either we clear the level and gain the value written on it, or we skip a contiguous block of levels and pay a penalty equal to the…

codeforcescompetitive-programming