instruction
stringlengths
0
29.8k
⌀
null
null
null
null
Assume that the graph is non-empty, pick an arbitrary vertex $s$ and construct the first $\lceil \log n \rceil$ levels of the BFS tree $T$ from $s$. You will encounter some non-tree edge $(u,v)$ in the process. This is trivially true when $n=4$, as the only possible graph that satisfies the degree constraints is $K...
I'm reading a text book on CPU architecture and I have something that confuses me: The text book defines 4 different instruction execution models in CPUs, Stack (where a CPU only has a stack and is able to perform operations on the first and second elements of the stack and push the result back), Accumulator (the CPU l...
RISC-V execution model
|computer-architecture|cpu|risc-v|
null
Let HALT be a program that can decide the halting problem for any program and its input. HALT has two inputs, the program and the program's input. Let OPPOSITE be a program that accepts a program as input, calls HALT with its input as both of HALT's inputs, and then does the opposite of whatever HALT has concluded. ...
Let HALT be a program that can decide the halting problem for any program and its input. HALT has two inputs, the program and the program's input. Let OPPOSITE be a program that accepts a program as input, calls HALT with its input as both of HALT's inputs, and then does the opposite of whatever HALT has concluded. ...
null
Yes, you seem to have made at least one error. Programs don't "know" anything. That was the first error I spotted, and then I stopped reading, as a single logical error invalidates an argument. Therefore, the statement "Let us further assume that HALT knows it can decide the halting problem" is meaningless and nonse...
I looked through `Java`'s `Random` class and saw that the initial seed is created using: public Random() { this(seedUniquifier() ^ System.nanoTime()); } But every consecutive seed is derived from old seed using:`nextseed = (oldseed * multiplier + addend) & mask;` Why is that? Why not ...
Why are seeds connected in Linear Congruential Generators?
|randomness|pseudo-random-generators|random-number-generator|
I am reading "An Introduction to the Analysis of Algorithms" by Robert Sedgewick and Kevin Wayne. In this book, Exercise 1.4 asks to develop a recurrence for $C_{N+1} - C_{N}$ and use it to prove that $$C_N = \sum_{1\leq k < N}{(\lfloor\lg{k}\rfloor + 2)}$$ where $C_{N}$ is the number of compares of mergesort. ...
Recurrence for C(N+1) - C(N) of mergesort
|time-complexity|mergesort|
In the terminology that you're using, RISC-V is a register-register ISA. For integer and floating point instructions: - All arithmetic and logic operations take registers as operands and write the result to a register. - The only operations that access memory are load and store operations. - There is no dedi...
The first time your program asks for the system time, it's more or less random. Specifically, if the clock really does have nanosecond resolution, then the lowest-order 30 bits or so are truly unpredictable. The second time your program asks for the system time, your deterministic program receives a number that is q...
[Wikipedia](https://en.wikipedia.org/wiki/Asymptotic_analysis) and other sources define "asymptotically equivalent" as: two functions $f$ and $g$ are asymptotically equivalent if: $$ \lim\limits_{x \to\infty}\frac{f(x)}{g(x)}=1 $$ But we regard $n^2$ and $2n^2$ as asymptotically equivalent, and these always hav...
[Wikipedia](https://en.wikipedia.org/wiki/Asymptotic_analysis) and other sources define "asymptotically equivalent" as: two functions $f$ and $g$ are asymptotically equivalent if: $$ \lim\limits_{x \to\infty}\frac{f(x)}{g(x)}=1 $$ But we regard $n^2$ and $2n^2$ as asymptotically equivalent, and these always hav...
[Wikipedia](https://en.wikipedia.org/wiki/Asymptotic_analysis) and other sources define "asymptotically equivalent" as: two functions $f$ and $g$ are asymptotically equivalent if: $$ \lim\limits_{x \to\infty}\frac{f(x)}{g(x)}=1 $$ But we regard $n^2$ and $2n^2$ as asymptotically equivalent, and these always hav...
[Wikipedia](https://en.wikipedia.org/wiki/Asymptotic_analysis) and other sources define "asymptotically equivalent" as: two functions $f$ and $g$ are asymptotically equivalent if: $$ \lim\limits_{x \to\infty}\frac{f(x)}{g(x)}=1 $$ But we regard $n^2$ and $2n^2$ as asymptotically equivalent, and these always hav...
Suppose we have a bipartite graph with N vertices on either side. Number of possible matchings (i.e. assignments) = N! Number of edges in the bipartite graph = N * N Suppose few edges among the N * N edge set are "known" to be missing (or have infinite weight) So, how can we find the number of matchings in the...
Suppose we have a bipartite graph with $N$ vertices on either side. In the full bipartite graph, the number of edges is $N^2$ and the number of possible matchings (i.e. assignments) is $N!$. Now suppose a few ($O(1)$) edges are missing from the full bipartite graph. How can we find the number of matchings? Is...
null
Suppose we have a bipartite graph with $N$ vertices on either side. In the full bipartite graph, the number of edges is $N^2$ and the number of possible matchings (i.e. assignments) is $N!$. Now suppose a few known edges ($O(1)$ edges) are missing from the full bipartite graph. How can we find the number of matc...
The following code is from [GeeksForGeeks](https://www.geeksforgeeks.org/deletion-in-linked-list/) ``` void deleteN(Node** head, int position) { Node* temp; Node* prev; temp = *head; prev = *head; for (int i = 0; i < position; i++) { if (i == 0 && position == 1) { *head = (*head)->next; free(t...
Use of pointers in linked list
|data-structures|linked-lists|
**Laconic** This is the highest profile attempt I've heard of so far. It was announced on this paper by Adam Yedidia and [Scott Aaronson](https://www.scottaaronson.com/): https://www.scottaaronson.com/busybeaver.pdf and on this blog post by Scott: https://scottaaronson.blog/?p=2725 - repo toplevel on Adam's GitHu...
Let $V$ be a set of vectors over $\mathbb{R}^l$. Let $\pi_i(V)$ be the permutation of vectors in $V$ such that they are ordered by their $i$th component (descending), so $\pi_i(V)(\textbf{v})$ is the rank of $\textbf{v}$ by component $i$. Then define $top(V, k) := \sum_{i=0}^l \sum_{\textbf{v}: \pi_i(V)(\textbf...
Optimal top-k column subset
|optimization|linear-algebra|
I am reading "An Introduction to the Analysis of Algorithms" by Robert Sedgewick and Kevin Wayne. In this book, Exercise 1.4 asks to develop a recurrence for $C_{N+1} - C_{N}$ and use it to prove that $$C_N = \sum_{1\leq k < N}{(\lfloor\lg{k}\rfloor + 2)}$$ where $C_{N}$ is the number of compares of mergesort. ...
That's poorly written, confusing code, and it would be better not to study it too closely. That said, there is a good reason it takes a `Node**`. The pointer to the first node may change when deleting a node, if the deleted node is the first one, so `deleteN` has to communicate the new value to the caller. It could hav...
**Laconic** This is the highest profile attempt I've heard of so far. It was announced on this paper by Adam Yedidia and [Scott Aaronson](https://www.scottaaronson.com/): https://www.scottaaronson.com/busybeaver.pdf and on this blog post by Scott: https://scottaaronson.blog/?p=2725 - repo toplevel on Adam's GitHu...
In deleteN, head needs to be a pointer to pointer, because its value might be modified in the function (due to that miserable lack of by-reference argument passing). In printList, it is a plain pointer. Note that calling both arguments the same way is poor practice (ppHead and pHead could have been better; this emph...
Let $V$ be a set of vectors over $\mathbb{R}^l$, $l\ge 1$, $\pi_i(V)$ be the permutation of vectors in $V$ such that they are ordered by their $i$th component (descending) in order for $\pi_i(V)(\mathbf{v})$ to be the rank of $\textbf{v}$ by component $I$: then define $$ \operatorname{top}(V, k) := \sum_{i=0}^l \sum...
[Wikipedia](https://en.wikipedia.org/wiki/Asymptotic_analysis) and other sources define "asymptotically equivalent" as: two functions $f$ and $g$ are asymptotically equivalent if: $$ \lim\limits_{x \to\infty}\frac{f(x)}{g(x)}=1 $$ But we regard $n^2$ and $2n^2$ as asymptotically equivalent, and these always hav...
Given a sorted array where every element is distinct, we need to evaluate product of every difference, modulo $ 10^9 + 7 $ $$ \prod_{i < j} (arr[j] - arr[i]) \% (10^9 + 7) $$ Best approach I can think of is finding frequency of primes in product by grouping elements with same modular residue, which allows $ O(N *...
product of every difference
|discrete-mathematics|number-theory|divide-and-conquer|polynomials|fast-fourier-transform|
This question is from Exercise 1.7 in the book *An Introduction to the Analysis of Algorithms* by Robert Sedgewick and Kevin Wayne. > Assume that the running time of mergesort is $cN\lg{N}+ dN$, where $c$ and $d$ are machine-dependent constants. Show that if we implement the program on a particular machine and obser...
How to estimate T(2N) from T(N) of mergesort?
|time-complexity|
In search of an efficient data structure to store some sort of list hash that I can compare to a value to obtain a probability of it already being in the list. Perhaps it makes more sense defined as follows: Given a multiset $$X_n:=\{x_i \ | \ \ 0 \leq i\leq n\}$$ we define a singular value (or finite set of v...
Data structure for detecting duplicate entries efficiently
|data-structures|cryptography|bloom-filters|
In search of an efficient data structure to store some sort of list hash that I can compare to a value to obtain a probability of it already being in the list. Perhaps it makes more sense defined as follows: Given a multiset $$X_n:=\{x_i \ | \ \ 0 \leq i\leq n\}$$ we define a singular value (or finite set of v...
null
$$\frac{t_{2N}}{t_N}=\frac{2cN\lg(2N)+2dN}{cN\lg(N)+dN}=2\frac{c\lg(N)+c+d}{c\lg(N)+d}=2\left(1+\frac1{\lg(N)+\dfrac dc}\right)$$ and the claim seems wrong.
$$\frac{t_{2N}}{2t_N}=\frac{2cN\lg(2N)+2dN}{2cN\lg(N)+2dN}=\frac{c\lg(N)+c+d}{c\lg(N)+d}=1+\frac1{\lg(N)+\dfrac dc}$$ and the claim seems wrong.
$$\frac{t_{2N}}{2t_N}=\frac{2cN\lg(2N)+2dN}{2cN\lg(N)+2dN}=\frac{c\lg(N)+c+d}{c\lg(N)+d}=1+\frac1{\lg(N)+\dfrac dc}$$ and the claim seems wrong. ---------- Assuming that $c=d$, for the error to be less than $1\%$, $N$ should be at least $2^{99}$ !
We have $3n$ items with profits $p_1, \dots, p_{3n}$ (sum = $P$) and weights $w_1,\dots,w_{3n}$ (sum = $W$). We want to determine whether we can choose **exactly** $n$ items with profit at least $P/2$ and weight at most $W/2$. Is this problem NP-hard? It is very similar to the usual knapsack problem, but the cons...
Knapsack with fixed size
|np-hard|knapsack-problems|
I'm trying to understand David Pisinger's balanced algorithm for the subset-sum problem with bounded weights, which can be found on page 5 of his paper *Linear Time Algorithms for Knapsack Problems with Bounded Weights* ([link](https://sci-hub.yncjkj.com/10.1006/jagm.1999.1034)). Before asking this question I have read...
Understanding David Pisinger's balanced algorithm for the subset-sum problem with bounded weights
|correctness-proof|knapsack-problems|amortized-analysis|subset-sum|
null
null
I am trying to teach myself asymptotic notations. I feel like I'm in over my head. I read the explanations in the text book, and Khan Academy. But when I try to do proofs, I can't grasp anything. I'm trying to prove that If f (n) = ω(g(n)), then f (n) is not in O(g(n)) or o(g(n)). I know that they don't interse...
Proving asymptotic classes
|algorithm-analysis|asymptotics|
null
null
null
null
The problem is NP-Hard. You can reduce from the partition problem: given a multi-set $X = \{x_1, \dots, x_n\}$ of non-negative integers, is there a subset $S$ of $X$ such that $\sum_{x \in S} x = \frac{1}{2} \sum_{x \in X} x$? To obtain an instance of your problem you can create one $y_i$ for each integer $x_i$ and ...
null
null
null
In quantum computing, there is an error correcting code called the color code where each error in the bulk of the code produces three types of symptoms (one red, one green, one blue). Pairs of errors can push a symptom of one color around. The task of decoding is to find a minimal set of errors that merge the given sym...
Looking for name of problem similar to Steiner trees but with an RGB balancing constraint (color code decoding)
|reference-request|
We have a $N \times N$ cost matrix where the cost denotes the amount incurred for assigning a worker to a task. The number of possible assignments is $N!$. Let us call this set of all possible assignments as $Z$. Assume we have a subset $S$ of assignments from the $N!$ possible assignments. How can I get on...
Find an assignment discarding a subset of possible assignments
|graphs|combinatorics|matching|bipartite-matching|assignment-problem|
I'm studying the convex hull algorithms in the high dimensions. There were two papers by [Bernard Chazelle][1] and [T.M. Chan][2] from the 90s, to have achieved the at then the state of the art complexity. However, when I tried to find the recent papers, most of ones I found was about the "approximation" of the convex ...
The updated convex hull algorithms in 2023?
|linear-programming|convex-hull|
null
null
Preface: Knowledge representation is a fundamental concept in artificial intelligence (AI) that involves creating models and structures to represent information and knowledge in a way that intelligent systems can use. Let HALT be a program that can decide the halting problem for any program and its input. HALT has...
Preface: Knowledge representation is a fundamental concept in artificial intelligence (AI) that involves creating models and structures to represent information and knowledge in a way that intelligent systems can use. We will say a program knows something if it has the information encoded into it. Let HALT be a prog...
Preface: Knowledge representation is a fundamental concept in artificial intelligence (AI) that involves creating models and structures to represent information and knowledge in a way that intelligent systems can use. We will say a program knows something if it has the information encoded into it in a usable way. Le...
null
I am not an expert with functional programming. What I know is that the bag data structure satisfies the definition of a monad. There are two different implementations of Bag: one with linked lists, B1, and one with hash maps, B2. In B2, you are storing integers that are the multiplicities. I want to know: 1. Is...
Are these two implementations of Bag different monads?
|data-structures|functional-programming|
I am not an expert with functional programming. What I know is that the bag data structure satisfies the definition of a monad. There are two different implementations of Bag: one with linked lists, B1, and one with hash maps, B2. In B2, you are storing integers that are the multiplicities. I want to know: 1. Ar...
In category theory, we are taught that polymorphic functions correspond to dinatural transformations between functors of mixed variance, a k a multivariant natural transformations $\operatorname{G} \in \mathbf{Set^{op}} \times \mathbf{Set} \to \mathbf{Set}$. I have been investigating another view and wonder if any...
Does lambda calculus become covariant if you fix the base type instead of the lambda calculus term?
|reference-request|lambda-calculus|semantics|category-theory|
In category theory, we are taught that polymorphic functions correspond to dinatural transformations, a k a multivariant natural transformations between functors of mixed variance $\operatorname{G} \in \mathbf{Set^{op}} \times \mathbf{Set} \to \mathbf{Set}$, if there is one type variable. I have been investigating...
In category theory, we are taught that polymorphic functions correspond to dinatural transformations, a k a multivariant natural transformations between functors of mixed variance $\operatorname{G} \in \mathbf{Set^{op}} \times \mathbf{Set} \to \mathbf{Set}$, if there is one type variable. I have been investigating...
**Laconic** This is the highest profile attempt I've heard of so far. It was announced on this paper by Adam Yedidia and [Scott Aaronson](https://www.scottaaronson.com/): https://www.scottaaronson.com/busybeaver.pdf and on this blog post by Scott: https://scottaaronson.blog/?p=2725 - repo toplevel on Adam's GitHu...