brain
tamnd's digital brain — notes, problems, research
43815 notes
We need to solve Exercise 22 from Section 5.
We are given integers \(k \ge t \ge 2\) and set \(n = 2^k + 2^{k+1-t}\).
We consider the problem of finding the second largest element among \(n\) distinct elements using comparisons.
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...
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.
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).
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.
We need to solve Exercise 34 from TAOCP Volume 3, Section 5.
We need to determine \(S(16)\), the minimum number of comparisons required to sort 16 distinct elements in the worst case.
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...
Let \(f(x)\) denote the minimum possible weighted path length (WPL) of a real‑valued search tree of order \(x\) and resolution \(1\).
Let \(G\) be a finite directed acyclic graph (DAG).
We need to solve exercise 31 from Volume 3, Section 5.
Let \(S_e(n)\) denote the minimum worst-case number of comparison-exchanges required to sort \(n\) distinct elements, as defined in Exercise 30.
We work with the definitions given in the exercise.
We model the algorithm as a binary decision tree $T$.
We consider the problem of sorting 7 distinct elements using only binary comparisons.
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.
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.
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(...
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.
The minimum average number of comparisons for sorting \(n\) distinct elements is achieved by a comparison tree (a full binary tree) with \(n!
The information-theoretic lower bound \(\lceil \lg n!
Let \(T\) be an extended binary tree.
An **extended binary tree** is a finite rooted tree in which every internal node has exactly two children.
Let \(F(n)\) denote the number of comparisons performed by the merge‑insertion (Ford-Johnson) algorithm when sorting \(n\) distinct elements.
We consider the problem of constructing a minimum-comparison sorting tree for \(n\) distinct elements \(K_1,\dots,K_n\).
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...
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,.
The maximum number of comparisons for binary insertion is given in the text (Eq.
We consider the **merge insertion** (Ford-Johnson) algorithm as described in the text.
We need to solve exercise 14 from TAOCP Vol 3, section 5.
Let $T$ be a comparison tree with no redundant comparisons.
We need to solve Exercise 15 from TAOCP Volume 3, Section 5.
We consider the problem of sorting \(n\) elements whose keys are known to be either 0 or 1.
We consider the problem of sorting \(n\) elements when it is known that each key is either \(0\) or \(1\).
**Algorithm S (Radix list sort for variable‑length strings).
**Theorem T (Tamminen).
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.
We consider the problem of sorting \(N\) records with keys that are two-digit numbers in base \(M = \lceil \sqrt{N} \rceil\).
We consider the same record structure as in Algorithm R (Section 5.
We consider the railway switching network with \(n\) stacks as depicted in Fig.
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\).
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]\)...
The input file consists of the 16 three‑digit numbers (with leading zeros) \[ \begin{array}{c|c} \text{index} & \text{value} \\ \hline 1 & 503 \\
We are given a file of \(N\) records stored in a random-access memory as a single array \(R[1.
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.
We modify Algorithm L (List merge sort) as follows.
We consider the railway network with $n$ stacks in parallel shown in Fig.
Program L is the MIX implementation of Algorithm S (straight two-way merge sort) from Section 5.
We present **Algorithm L3**, a straight three-way merge sort for linked lists.
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...
We need to solve exercise 34: "How many leftist trees with N nodes are possible, ignoring the KEY values?
The redundancy occurs in the main merge loop of Algorithm L.
Algorithm L is the straight two-way merge sort described in the text.
We revise step L1 of Algorithm L (List merge sort) as follows.
**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...
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\).
Algorithm L (List merge sort) is a stable sorting method.
We need to solve Exercise 37 from TAOCP Vol 3, Section 5.
The subtree sizes of a complete binary tree with \(N\) internal nodes (or equivalently, of a heap of \(N\) elements) satisfy the following recurrence.
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).
We need to solve Exercise 32 from Section 5.
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...
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...
We are given exercise 30 from Volume 3, Section 5.
A *leftist tree* is a binary tree in which each node contains a key and a *null path length* (denoted `dist`).
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...
We need to solve Exercise 25 from TAOCP Volume 3, Section 5.
Solution to TAOCP 5.2.3 Exercise 29.
A **ternary heap** is a complete ternary tree stored in an array `A[1.
The identity is an equality of formal power series (or absolutely convergent series for \(|x|<1\)).
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).
We first recall the relevant definitions from the text.
We consider the heap creation phase of Algorithm H (heapsort) as described in Section 5.
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\).
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\)...
We need to solve exercise 56 from TAOCP Volume 3, Section 5.
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.
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.
Let the heap be stored in an array `K[1.
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.
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.
The selection phase of heapsort (Algorithm H) repeatedly extracts the maximum element from a heap of size \(N\).
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.
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.
We have a grid of lowercase letters with n rows and m columns. Removing a column means deleting that character position from every row.
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.
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.
In Program Q (Quicksort), step Q3 (lines 4H-6H) chooses the first element of the current subfile as the partitioning element.
No, the two methods do not always create the same heap.
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.
The room is a rectangle of unit squares with dimensions N by M. Isabelle wants to cover every square using identical L-shaped tiles.
**Algorithm I** (*Heap insertion*).
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.
We need to solve Exercise 42 from Volume 3, Section 5.
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.
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.
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.
We are given the contour integral representation U_n = (-1)^n \frac{n!