brain

tamnd's digital brain — notes, problems, research

43815 notes

TAOCP 5.3.3 Exercise 22

We need to solve Exercise 22 from Section 5.

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.3.3 Exercise 21

We are given integers \(k \ge t \ge 2\) and set \(n = 2^k + 2^{k+1-t}\).

taocpmathematicsalgorithmsvolume-3hard
TAOCP 5.3.3 Exercise 20

We consider the problem of finding the second largest element among \(n\) distinct elements using comparisons.

taocpmathematicsalgorithmsvolume-3math-project
TAOCP 5.3.3 Exercise 23

We are asked for the asymptotic value of \(V_{\lceil n/2 \rceil}(n)\) as \(n\to\infty\), where \(V_t(n)\) is the minimum number of comparisons required in the worst case to determine the \(t\)‑th larg...

taocpmathematicsalgorithmsvolume-3math-project
TAOCP 5.3.3 Exercise 19

Let \(V_t(n)\) denote the minimum number of comparisons required to select the \(t\)‑th largest element from a set of \(n\) elements, as defined in Section 5.

taocpmathematicsalgorithmsvolume-3math-project
TAOCP 5.3.3 Exercise 17

We combine the algorithm of Exercise 16 (finding the maximum and minimum simultaneously) with the tree‑selection method of Kislitsyn’s theorem (formula (6) in the text).

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.3.3 Exercise 18

The median-of-medians algorithm (Blum, Floyd, Pratt, Rivest, Tarjan) finds the \(t\)th largest element by recursively using a pivot obtained as the median of medians of small groups.

taocpmathematicsalgorithmsvolume-3math-medium
TAOCP 5.3.1 Exercise 34

We need to solve Exercise 34 from TAOCP Volume 3, Section 5.

taocpmathematicsalgorithmsvolume-3math-research
TAOCP 5.3.1 Exercise 35

We need to determine \(S(16)\), the minimum number of comparisons required to sort 16 distinct elements in the worst case.

taocpmathematicsalgorithmsvolume-3hard
TAOCP 5.3.2 Exercise 13

We consider the recurrence from Exercise 12 for $R_n(i,j)$ with $1 \le i \le j \le n$: \[ R_n(i,j) = 1 + \min\Bigl(\, \min_{1\le k\le i} \max\bigl(R_n(k-1,j),\, R_{n-k}(i-k,j)\bigr),\, \min_{1\le k\le...

taocpmathematicsalgorithmsvolume-3math-project
TAOCP 5.3.1 Exercise 33

Let \(f(x)\) denote the minimum possible weighted path length (WPL) of a real‑valued search tree of order \(x\) and resolution \(1\).

taocpmathematicsalgorithmsvolume-3math-hard
TAOCP 5.3.1 Exercise 36

Let \(G\) be a finite directed acyclic graph (DAG).

taocpmathematicsalgorithmsvolume-3math-research
TAOCP 5.3.1 Exercise 31

We need to solve exercise 31 from Volume 3, Section 5.

taocpmathematicsalgorithmsvolume-3math-project
TAOCP 5.3.1 Exercise 32

Let \(S_e(n)\) denote the minimum worst-case number of comparison-exchanges required to sort \(n\) distinct elements, as defined in Exercise 30.

taocpmathematicsalgorithmsvolume-3math-project
TAOCP 5.3.1 Exercise 30

We work with the definitions given in the exercise.

taocpmathematicsalgorithmsvolume-3math-hard
TAOCP 5.3.1 Exercise 29

We model the algorithm as a binary decision tree $T$.

taocpmathematicsalgorithmsvolume-3math-medium
TAOCP 5.3.1 Exercise 26

We consider the problem of sorting 7 distinct elements using only binary comparisons.

taocpmathematicsalgorithmsvolume-3math-project
TAOCP 5.3.1 Exercise 24

We are asked to find a comparison tree (sorting tree) for six distinct elements such that all 720 external nodes (leaves) appear on levels 10 and 11.

taocpmathematicsalgorithmsvolume-3hard
TAOCP 5.3.1 Exercise 27

We are given the six possible orders of three distinct keys \(K_1, K_2, K_3\) with their probabilities: \[ \begin{array}{c|c} \text{Order} & \text{Probability} \\ \hline K_1 < K_2 < K_3\;(123) & 0.

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.3.1 Exercise 22

We prove that an extended binary tree has minimum external path length among all extended binary trees with the same number \(N\) of external nodes **iff** for every internal node \(x\) \[ |t(x)-2\,t(...

taocpmathematicsalgorithmsvolume-3math-medium
TAOCP 5.3.1 Exercise 14

The sum (19) in the text is the total number of comparisons required by merge insertion to sort \(n\) elements, which is \[ S(n) = \sum_{k=1}^n \left\lceil \log_2 \frac{3k}{4} \right\rceil.

taocpmathematicsalgorithmsvolume-3math-medium
TAOCP 5.3.1 Exercise 25

The minimum average number of comparisons for sorting \(n\) distinct elements is achieved by a comparison tree (a full binary tree) with \(n!

taocpmathematicsalgorithmsvolume-3simple
TAOCP 5.3.1 Exercise 23

The information-theoretic lower bound \(\lceil \lg n!

taocpmathematicsalgorithmsvolume-3simple
TAOCP 5.3.1 Exercise 21

Let \(T\) be an extended binary tree.

taocpmathematicsalgorithmsvolume-3math-medium
TAOCP 5.3.1 Exercise 20

An **extended binary tree** is a finite rooted tree in which every internal node has exactly two children.

taocpmathematicsalgorithmsvolume-3math-hard
TAOCP 5.3.1 Exercise 16

Let \(F(n)\) denote the number of comparisons performed by the merge‑insertion (Ford-Johnson) algorithm when sorting \(n\) distinct elements.

taocpmathematicsalgorithmsvolume-3hm-hard
TAOCP 5.3.1 Exercise 19

We consider the problem of constructing a minimum-comparison sorting tree for \(n\) distinct elements \(K_1,\dots,K_n\).

taocpmathematicsalgorithmsvolume-3project
TAOCP 5.3.1 Exercise 18

The efficiency of a comparison tree that sorts \(n\) elements (with no redundant comparisons) is defined as the number of leaves divided by \(2^{h}\), where \(h\) is the height of the tree (the maximu...

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.3.1 Exercise 11

We need to solve exercise 11: "When sorting n elements as in exercise 5, and knowing that all keys are members of the set {1,2,.

taocpmathematicsalgorithmsvolume-3hm-medium
TAOCP 5.3.1 Exercise 15

The maximum number of comparisons for binary insertion is given in the text (Eq.

taocpmathematicsalgorithmsvolume-3math-medium
TAOCP 5.3.1 Exercise 13

We consider the **merge insertion** (Ford-Johnson) algorithm as described in the text.

taocpmathematicsalgorithmsvolume-3math-hard
TAOCP 5.2.5 Exercise 14

We need to solve exercise 14 from TAOCP Vol 3, section 5.

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.3.1 Exercise 12

Let $T$ be a comparison tree with no redundant comparisons.

taocpmathematicsalgorithmsvolume-3math-medium
TAOCP 5.2.5 Exercise 15

We need to solve Exercise 15 from TAOCP Volume 3, Section 5.

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.3.1 Exercise 10

We consider the problem of sorting \(n\) elements whose keys are known to be either 0 or 1.

taocpmathematicsalgorithmsvolume-3math-medium
TAOCP 5.3.1 Exercise 9

We consider the problem of sorting \(n\) elements when it is known that each key is either \(0\) or \(1\).

taocpmathematicsalgorithmsvolume-3math-medium
TAOCP 5.2.5 Exercise 16

**Algorithm S (Radix list sort for variable‑length strings).

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.2.5 Exercise 18

**Theorem T (Tamminen).

taocpmathematicsalgorithmsvolume-3hm-hard
TAOCP 5.2.5 Exercise 17

In Tamminen's two-level distribution sort (Theorem T), the first level partitions the $N$ records into $M$ buckets according to their most significant digit.

taocpmathematicsalgorithmsvolume-3simple
TAOCP 5.2.5 Exercise 13

We consider the problem of sorting \(N\) records with keys that are two-digit numbers in base \(M = \lceil \sqrt{N} \rceil\).

taocpmathematicsalgorithmsvolume-3project
TAOCP 5.2.5 Exercise 10

We consider the same record structure as in Algorithm R (Section 5.

taocpmathematicsalgorithmsvolume-3hard
TAOCP 5.2.4 Exercise 19

We consider the railway switching network with \(n\) stacks as depicted in Fig.

taocpmathematicsalgorithmsvolume-3hard
TAOCP 5.2.5 Exercise 12

After Algorithm R has processed the \(p\) leading digits, the records \(R_1,\dots,R_N\) are linked together in a list that starts at pointer \(P\).

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.2.4 Exercise 22

We consider the problem of sorting \(N\) records \(R_1,\dots,R_N\) whose keys are **multiword**: each key \(K_i\) consists of \(W\) words \[ K_i = (K_i[1], K_i[2], \dots, K_i[W]), \] where \(K_i[1]\)...

taocpmathematicsalgorithmsvolume-3hard
TAOCP 5.2.5 Exercise 11

The input file consists of the 16 three‑digit numbers (with leading zeros) \[ \begin{array}{c|c} \text{index} & \text{value} \\ \hline 1 & 503 \\

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.2.4 Exercise 18

We are given a file of \(N\) records stored in a random-access memory as a single array \(R[1.

taocpmathematicsalgorithmsvolume-3project
TAOCP 5.2.4 Exercise 23

The top-down (divide-and-conquer) merge sort splits a file of \(N\) records into two subfiles of sizes \(\lceil N/2\rceil\) and \(\lfloor N/2\rfloor\), sorts them recursively, and merges the results.

taocpmathematicsalgorithmsvolume-3math-hard
TAOCP 5.2.4 Exercise 21

We modify Algorithm L (List merge sort) as follows.

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.2.4 Exercise 20

We consider the railway network with $n$ stacks in parallel shown in Fig.

taocpmathematicsalgorithmsvolume-3research
TAOCP 5.2.4 Exercise 13

Program L is the MIX implementation of Algorithm S (straight two-way merge sort) from Section 5.

taocpmathematicsalgorithmsvolume-3math-hard
TAOCP 5.2.4 Exercise 16

We present **Algorithm L3**, a straight three-way merge sort for linked lists.

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.2.4 Exercise 17

We maintain the invariant that the $N$ records are distributed among a set of stacks (or lists) $S_0, S_1, S_2, \ldots$, where each stack $S_k$ either is empty or contains exactly one sorted run (subf...

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.2.3 Exercise 34

We need to solve exercise 34: "How many leftist trees with N nodes are possible, ignoring the KEY values?

taocpmathematicsalgorithmsvolume-3math-project
TAOCP 5.2.4 Exercise 15

The redundancy occurs in the main merge loop of Algorithm L.

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.2.4 Exercise 14

Algorithm L is the straight two-way merge sort described in the text.

taocpmathematicsalgorithmsvolume-3math-medium
TAOCP 5.2.4 Exercise 12

We revise step L1 of Algorithm L (List merge sort) as follows.

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.2.4 Exercise 9

**Register assignment** rI1 = i (left source pointer) rI2 = j (right source pointer) rI3 = k (destination pointer) rI5 = q (elements left in current left run) rI6 = r (elements left in current right r...

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.2.4 Exercise 10

We show that straight two-way merge sort (Algorithm S) can be implemented using a single sequentially allocated memory area of size \(N + \lceil N/2\rceil \le \lceil 3N/2\rceil\).

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.2.4 Exercise 11

Algorithm L (List merge sort) is a stable sorting method.

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.2.3 Exercise 37

We need to solve Exercise 37 from TAOCP Vol 3, Section 5.

taocpmathematicsalgorithmsvolume-3hm-hard
TAOCP 5.2.3 Exercise 38

The subtree sizes of a complete binary tree with \(N\) internal nodes (or equivalently, of a heap of \(N\) elements) satisfy the following recurrence.

taocpmathematicsalgorithmsvolume-3math-medium
TAOCP 5.2.3 Exercise 24

We need to derive an exact formula for the standard deviation of B_N, the total length of scan during the heap-creation phase of Algorithm H (Heapsort).

taocpmathematicsalgorithmsvolume-3math-hard
TAOCP 5.2.3 Exercise 32

We need to solve Exercise 32 from Section 5.

taocpmathematicsalgorithmsvolume-3math-hard
TAOCP 5.2.3 Exercise 36

The required data structure is a **doubly linked list** (or a circular doubly linked list with a sentinel node) that maintains the nodes in order of recency of use, with the most recently used node at...

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.2.3 Exercise 35

A **leftist tree** is a binary tree where each node \(x\) has a field \(\operatorname{DIST}(x)\) defined as \[ \operatorname{DIST}(x) = \begin{cases} 0 & \text{if } x \text{ is external (null)}, \\ 1...

taocpmathematicsalgorithmsvolume-3hard
TAOCP 5.2.3 Exercise 30

We are given exercise 30 from Volume 3, Section 5.

taocpmathematicsalgorithmsvolume-3hm-medium
TAOCP 5.2.3 Exercise 33

A *leftist tree* is a binary tree in which each node contains a key and a *null path length* (denoted `dist`).

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.2.3 Exercise 31

We represent the priority deque as a **deap** (double-ended heap), which consists of a min‑heap and a max‑heap placed “back to back” in a single array that stores a complete binary tree with a dummy r...

taocpmathematicsalgorithmsvolume-3project
TAOCP 5.2.3 Exercise 25

We need to solve Exercise 25 from TAOCP Volume 3, Section 5.

taocpmathematicsalgorithmsvolume-3math-medium
TAOCP 5.2.3 Exercise 29

Solution to TAOCP 5.2.3 Exercise 29.

taocpmathematicsalgorithmsvolume-3hard
TAOCP 5.2.3 Exercise 28

A **ternary heap** is a complete ternary tree stored in an array `A[1.

taocpmathematicsalgorithmsvolume-3hard
TAOCP 5.2.3 Exercise 27

The identity is an equality of formal power series (or absolutely convergent series for \(|x|<1\)).

taocpmathematicsalgorithmsvolume-3math-medium
TAOCP 5.2.2 Exercise 52

Let \[ S_n=\sum_{t\ge 1}\binom{2n}{n+t}d(t),\qquad C_n=\binom{2n}{n}, \qquad R_n=\frac{S_n}{C_n}=\sum_{k=1}^{n}\frac{\binom{2n}{n+k}}{C_n}\,d(k).

taocpmathematicsalgorithmsvolume-3hm-hard
TAOCP 5.2.3 Exercise 21

We first recall the relevant definitions from the text.

taocpmathematicsalgorithmsvolume-3math-medium
TAOCP 5.2.3 Exercise 23

We consider the heap creation phase of Algorithm H (heapsort) as described in Section 5.

taocpmathematicsalgorithmsvolume-3math-hard
TAOCP 5.2.3 Exercise 22

The heapcreation phase of Algorithm H (heapsort) for \(N = 5\) builds a heap by applying the sift-down operation first at node \(2\) and then at node \(1\).

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.2.3 Exercise 20

We consider a heap of size \(N\) stored in an array \(1,2,\ldots,N\) as a complete binary tree: the root is at index \(1\); for any node \(k\), its left child is \(2k\) and its right child is \(2k+1\)...

taocpmathematicsalgorithmsvolume-3math-medium
TAOCP 5.2.2 Exercise 56

We need to solve exercise 56 from TAOCP Volume 3, Section 5.

taocpmathematicsalgorithmsvolume-3math-medium
CF 102739G - План Д

We have n independent subtasks that must be completed during m consecutive days. Each subtask has an allowed time interval: it can be done on any day from si to fi.

codeforcescompetitive-programming
CF 102739F - Саша опять делает задачу про простые числа

The task is to make every fitness tracker value acceptable to Sasha. A value is acceptable if it is either a prime number or a power of two. For each recorded number, we need to find the smallest acceptable number that is not smaller than the recording.

codeforcescompetitive-programming
TAOCP 5.2.3 Exercise 19

Let the heap be stored in an array `K[1.

taocpmathematicsalgorithmsvolume-3medium
CF 102739C - Под дождём

Polina has a fixed route home. The first part of the route is an uncovered street that takes t1 minutes, and the second part is an alley under trees that takes t2 minutes. She may choose when to leave school, but she has to arrive no later than time d.

codeforcescompetitive-programming
CF 102740B - Clone Factory

The process starts with five named soldiers standing in a queue. A dose is always given to the soldier at the front. That soldier creates one identical clone, and both copies move to the back of the queue.

codeforcescompetitive-programming
TAOCP 5.2.3 Exercise 18

The selection phase of heapsort (Algorithm H) repeatedly extracts the maximum element from a heap of size \(N\).

taocpmathematicsalgorithmsvolume-3medium
CF 102740A - Valorant Score

I can write the full editorial, but the problem statement provided in your prompt is empty and the required sections depend on the exact statement details and constraints.

codeforcescompetitive-programming
CF 102740H - E. Gadd's Ghost Zapper

We have a long one-dimensional hallway. Some positions contain zapper devices, and some positions contain ghosts. A zapper can remove any ghost, but the energy cost depends on the square of the distance between them.

codeforcescompetitive-programming
CF 102740G - Letters Among Us

We have a grid of lowercase letters with n rows and m columns. Removing a column means deleting that character position from every row.

codeforcescompetitive-programming
CF 102740F - Special Salads

We have salad types numbered from 1 to 10^8. Each type has a price determined by rounding its number upward to the nearest lucky number. A lucky number is a positive integer whose decimal representation contains only the digits 3 and 8.

codeforcescompetitive-programming
CF 102740E - Kario Mart

The problem describes a rectangular grocery store floor with width w and height h. The possible race tracks are all rectangles whose corners lie on the grid lines of this floor.

codeforcescompetitive-programming
TAOCP 5.2.2 Exercise 55

In Program Q (Quicksort), step Q3 (lines 4H-6H) chooses the first element of the current subfile as the partitioning element.

taocpmathematicsalgorithmsvolume-3medium
TAOCP 5.2.3 Exercise 17

No, the two methods do not always create the same heap.

taocpmathematicsalgorithmsvolume-3medium
CF 102740D - Combo Counter

I can write the full editorial, but the problem statement for Codeforces 102740D - Combo Counter is missing from your prompt, and I could not reliably retrieve the statement from the problem ID alone.

codeforcescompetitive-programming
CF 102740C - Isabelle's Redecorating

The room is a rectangle of unit squares with dimensions N by M. Isabelle wants to cover every square using identical L-shaped tiles.

codeforcescompetitive-programming
TAOCP 5.2.3 Exercise 16

**Algorithm I** (*Heap insertion*).

taocpmathematicsalgorithmsvolume-3medium
CF 102741K - Crafty Explosions

The problem asks for the least volatility of one newly placed TNT piece so that every existing TNT piece is guaranteed to explode immediately. The new TNT can be placed at any real-valued position in three-dimensional space.

codeforcescompetitive-programming
TAOCP 5.2.2 Exercise 42

We need to solve Exercise 42 from Volume 3, Section 5.

taocpmathematicsalgorithmsvolume-3hm-hard
CF 102741J - E-Sports Tournament

The system maintains a social network of users. A friendship connection joins two users into the same friend group, where groups are connected components of the graph. For every tournament query, we are asked how many teams of exactly size s can be formed.

codeforcescompetitive-programming
CF 102741I - Stunt Jump Escape

The map is a grid of hills. Michael starts somewhere on the top edge and moves one row downward every minute, while Trevor starts somewhere on the left edge and moves one column to the right every minute.

codeforcescompetitive-programming
TAOCP 5.2.2 Exercise 50

We need to find the asymptotic value of U_{mn} = sum_{k >= 2} C(n,k) (-1)^k / (m^{k-1} - 1) for fixed m > 1 as n -> infinity.

taocpmathematicsalgorithmsvolume-3hm-medium
TAOCP 5.2.2 Exercise 54

We are given the contour integral representation U_n = (-1)^n \frac{n!

taocpmathematicsalgorithmsvolume-3hm-medium