instruction
stringlengths
0
29.8k
⌀
An inverse problem of lexicographic product of graphs
|graphs|
If I give you an additional hint, that the two items that are consistently compared incorrectly are adjacent in the correctly sorted array, and I’ve sorted the array for you already so that only these two items are not correctly sorted, then there is no way for you to find out which pair is ordered incorrectly. Ano...
I've had to do something along these lines. My solution: Pick one of the dimensions and divide it into 'buckets' of width equal to the threshold (only finitely many buckets are required for finitely many points). Then place each point into its bucket; when doing so, check for proximity to another point against all po...
null
null
I thought up this problem and am trying to come up with an optimal solution. >I am thinking of a number uniformly randomly between 1-100, inclusive. > - If you guess the number, you "win". > - Else if you guess incorrectly, but are within 10 of the number, I will tell you "hot". > - Else, I will tell you "cold...
|algorithms|binary-search|optimal-strategy|
PRNGs (pseudorandom number generators) generally have a bit length for the binary numbers they generate (e.g. 32 bits, 64 bits). This is the universe of their possible numbers. It seems that they typically cycle when they reach their 2^bitlen number. Is there one that, before it cycles, will generate each possibl...
Is there a PRNG that visits every number exactly once, in a non-trivial bitspace, without repetition, without large memory usage, before it cycles?
|pseudo-random-generators|
null
I'm not convinced that substitutions are associative, I read the https://en.wikipedia.org/wiki/Substitution_(logic)#First-order_logic and the https://www.youtube.com/watch?v=_cVNeccMF-E My problem is in this case, I use $\Rightarrow$ to mean _reduces to_ $( f(X,Y)\{X \rightarrow Y\} )\{Y\rightarrow X\} \\ \Right...
How substituituion composition is associative?
|first-order-logic|
As you have proven the composition $\{X\to Y\}\{Y \to X\}$ is not $\{X\to Y; Y\to X\}$. Also, that has nothing to do with associativity. See https://en.wikipedia.org/wiki/Associative_property.
Sure. Pick a block cipher (i.e., pseudorandom permutation), $E_K$, and a random key for it, $K$. Let $x_i=E_K(i)$. Then this has the properties you are looking for.
As you have proven the composition $\{X\to Y\}\{Y \to X\}$ is not $\{X\to Y; Y\to X\}$. Rather the composition is (assuming that it acts on terms to the left of it) $\{Y \to X\}$. Also, that has nothing to do with associativity. See https://en.wikipedia.org/wiki/Associative_property.
The data structure you are looking for is [double-ended queue (deque)](https://en.wikipedia.org/wiki/Double-ended_queue). It is basically what you have imagined, with the extra ease of operations on the front. Deque has been implemented in [many languages](https://en.wikipedia.org/wiki/Double-ended_queue#Operations)...
In graph theory, the [**lexicographic product**][1] or (graph composition) $G ∙ H$ of graphs $G$ and $H$ is a graph such that - the vertex set of $G ∙ H$ is the cartesian product $V(G) × V(H)$; - and any two vertices $(u,v)$ and $(x,y)$ are adjacent in $G ∙ H$ if and only if either $u$ is adjacent with $x$ in $...
null
Goal is proving grammar equivalence --- Upper-case symbols are non-terminal. Lower-case symbols are terminal. The start symbol is `S`. A grammar production rule is **non-terminals-only** if it only contains non-terminals. For example: `AB -> CDE` A grammar rule is **non-terminal-to-terminal** if the l...
Proving grammar equivalence in simple grammar (generate any sequence of three characters)
|formal-grammars|
Background: [How Percentile Approximation Works (and Why It’s More Useful Than Averages)](https://www.timescale.com/blog/how-percentile-approximation-works-and-why-its-more-useful-than-averages/) In traditional scenario, we store each value in an array/slice, in that case, we can just sort the array, and get the app...
How to approximate percentile value from value-count map?
|algorithms|
null
Compute the prefix sum of the counts, 67:5, 68:13, 70: 33, 71: 43, 76: 123, 78: 243, 79: 333, 80: 406, 98: 408 and find the value corresponding to `90%` of `408` = `367.2`. (Between `79` and `80`.)
Compute the prefix sum of the counts, 67:5, 68:13, 70: 33, 71: 43, 76: 123, 78: 243, 79: 333, 80: 406, 98: 408 and find the value corresponding to `90%` of `408` = `367.2`. (Between `79` and `80`.) [![enter image description here][1]][1] [1]: https://i.stack.imgur.com/XhirJ.png
null
null
Given a set B and B’s superset A, if B is missing 1 number but don’t know which number it is, how to find that number? So far, my thought is:\ xor all numbers in B = C \ C xor A = missing number and difference between 2 sets And I’m stuck at here.
Identify missing number in a set and given a superset
|algorithms|bit-manipulation|
Identify missing number in a set and given its superset
null
Consider simple random walks that stop when reaching a given node $x$ in an undirected, unweighted and connected graph on $n$ nodes. Let - $H(i,x)$ denote the (expected) hitting time from $i$ to $x$, with $H(x,x)=0$. - $H_{\max} = \max_{i \in V} H(i,x)$ and $H_{\text{avg}} = \frac{1}{n}\sum_{i \in V} H(i,x)$. ...
Average and max. hitting time to a specific vertex
|probability-theory|randomness|markov-chains|random-walks|
Given a set B and B’s superset A, if B is missing 1 number but don’t know which number it is, how to find that number? So far, my thought is:\ xor all numbers in A = C \ C xor B = missing number and difference between 2 sets And I’m stuck at here.
Suppose you have to prove the solution to the following recurrence by Induction, $$ T(n)= \begin{cases} \Theta(1), & n=1 \\ 2 T(\lfloor n/2 \rfloor)+\Theta(n), & n>1 \end{cases} $$ Here, $\Theta(1)$ and $\Theta(n)$ are notational abuse and they represent arbitrary positive constant and arbitrary linear funct...
How to resolve the clash between definition of Big O notation and Inductive Hypothesis when proving running time by substitution method?
|time-complexity|recurrence-relation|big-o-notation|induction|
For $1\ge p_1 \ge \dots \ge p_n \ge 0$, draw $n\times k$ iid binary strings with $m$ length: $$X_{i,1},\dots,X_{i,k}\stackrel{iid}{\sim} Bernoulli(p_i)^m, \qquad i\in[n].$$ Viewing these binary strings as integers, define their ranks as $$rank(i,s):=\#\{j\in[n]:X_{j,s}\ge X_{i,s}\}, \qquad MinRank(i):=\min_{s\in[k]}...
Order of random binary string with Bernoulli distribution
|sorting|probabilistic-algorithms|kd-tree|
For $1\ge p_1 \ge \dots \ge p_n \ge 0$, and for $i\in[n]$ draw $k$ iid binary strings with $m$ length: $$X_{i,1},\dots,X_{i,k}\stackrel{iid}{\sim} Bernoulli(p_i)^m.$$ Viewing these binary strings as integers, define their ranks as $$rank(i,s):=\#\{j\in[n]:X_{j,s}\ge X_{i,s}\}, \qquad MinRank(i):=\min_{s\in[k]} rank(...
What you asking about is [mathematical induction][1] theorem, more known as mathematical induction principle. It states, that $$\begin{cases}{} P(n_0) \text{ true} & \\ (\forall n \geqslant n_0)\big(P(n)\Rightarrow P(n+1)\big) & \end{cases} \Rightarrow (\forall n\geqslant n_0)P(n) $$ verbally it means, that fo...
For $1\ge p_1 \ge \dots \ge p_n \ge 0$, and for $i\in[n]$ draw $k$ iid binary strings with $m$ length: $$X_{i,1},\dots,X_{i,k}\stackrel{iid}{\sim} Bernoulli(p_i)^m.$$ Viewing these binary strings as integers, define their ranks as $$rank(i,s):=\#\{j\in[n]:X_{j,s}\ge X_{i,s}\}, \qquad MinRank(i):=\min_{s\in[k]} rank(...
What you asking about is [mathematical induction][1] theorem, more known as mathematical induction principle. It states, that $$\begin{cases}{} P(n_0) \text{ true} & \\ (\forall n \geqslant n_0)\big(P(n)\Rightarrow P(n+1)\big) & \end{cases} \Rightarrow (\forall n\geqslant n_0)P(n) $$ verbally it means, that fo...
Rank of random binary string with Bernoulli distribution
***Disclaimer:*** _I am a beginner and I am self-learning the presented concepts. I kindly ask you to take this into consideration while reading my question._ Hello, I have found [this question](https://cs.stackexchange.com/questions/151365/worst-case-lower-bound-of-the-general-number-guessing-problem) some time ...
What is the dependency relation between algorithms and models?
|algorithms|complexity-theory|time-complexity|turing-machines|algorithm-analysis|
null
I have found [this question](https://cs.stackexchange.com/questions/151365/worst-case-lower-bound-of-the-general-number-guessing-problem) some time ago. While reading it, I had a problem with understanding the following idea: ***Question A:*** _Is one allowed to talk about the time/space bound of any algorithm (e.g....
Relation between algorithms and models
Data only accessible in a scope, seems to still be maintained by the stack. What is the reason that entering and exiting scopes (in general) does not do the same ["prologue and epilogue" instructions][1] that are done when entering and exiting functions? What test1 and test2 show, in test2 8 byte is allocated in the...
Why scopes in general do not have prologue and epilogue instructions?
|cpu|assembly|instruction-set|
You have made an assumption about scopes in the C language which is not correct. Unlike general Algol family languages, C does not have infinitely nested scopes for every statement block. Although your have used the brackets `{}` inside a function, you have not created a new scope. the only scope present is that of ...
Suppose you have to prove the solution to the following recurrence by Induction, $$ T(n)= \begin{cases} \Theta(1), & n=1 \\ 2 T(\lfloor n/2 \rfloor)+\Theta(n), & n>1 \end{cases} $$ Here, $\Theta(1)$ and $\Theta(n)$ are notational abuse and they represent arbitrary positive constant and arbitrary linear funct...
Allowed probably isn't the right word. You can do anything you want. You can certainly have a lower bound without being sure whether it is tight or not. For instance, I can say that sorting takes at least $\Omega(n)$ time, without knowing whether there is an algorithm for sorting that runs in $O(n)$ time.
I have found [this question](https://cs.stackexchange.com/questions/151365/worst-case-lower-bound-of-the-general-number-guessing-problem) some time ago. While reading it, I had a problem with understanding the following idea: ***Question, part 1:*** _Is one allowed to talk about the time/space bound of any algorithm...
Allowed probably isn't the right word. You can do anything you want. You can certainly have a lower bound without being sure whether it is tight or not. For instance, I can say that sorting takes at least $\Omega(n)$ time, without knowing whether there is an algorithm for sorting that runs in $O(n)$ time. Perha...
You can prove grammar equivalence by showing that they represent the same language,use fixed pont iteration method to find language of context free grammar.
I don't undestand what is the difficulty you are having. If $B = A \setminus \{x\}$ for some element $x$, then: $$ \begin{align*} \left( \bigoplus_{b \in B} b \right) \oplus \left( \bigoplus_{a \in A} a \right ) &= \left( \bigoplus_{b \in B} b \right ) \oplus \left( \bigoplus_{a \in A \setminus {x}} a \right) ...
I don't undestand what is the difficulty you are having. If $B = A \setminus \{x\}$ for some element $x$, then: $$ \begin{align*} \left( \bigoplus_{b \in B} b \right) \oplus \left( \bigoplus_{a \in A} a \right ) &= \left( \bigoplus_{b \in B} b \right ) \oplus \left( \bigoplus_{a \in A \setminus {x}} a \right) ...
null
I got interested in one problem. I have $N$ rocks, where rock with minimum weight have number equal to $1$, the next heaviest stone has a number equal to 2, etc.. So a rock with maximum weight have a number equal to $N$. And I have $N$ requests, each of N request contains two integers: $R$ $(1≤R≤N)$ and $S$ $(1≤S≤...
Weigher problem
|algorithms|data-structures|
#### Two different biconnected components does not share an edge <!-- Path, simple path, cycle and simple cycle are defined in Appendix B.4 of that textbook. A path is a sequence $v_0, v_1, \ldots, v_k$ of vertices such that $(v_{i-1}, v_i)$ is an edge. A path is simple if all vertices in the path are distinct. ...
Here some progress. I'm assuming that no two rocks have the same weight. We model a generic bowl as as set $X\subseteq \{1,\dots, N\}$ whose elements are the indices of the stones contained in the bowl. Let $n(i,X)$ denote the $i$-th largest index in $X$. If $X$ contains less than $i$ stones, let $n(i,X) = 0$. Let ...
For $1\ge p_1 \ge \dots \ge p_n \ge 0$, and for $i\in[n]$ draw $k$ iid binary strings with $m$ length: $$X_{i,1},\dots,X_{i,k}\stackrel{iid}{\sim} \text{Bernoulli}(p_i)^m.$$ Viewing these binary strings as integers, define their ranks as $$\text{rank}(i,s):=\#\{j\in[n]:X_{j,s}\ge X_{i,s}\}, \qquad \text{MinRank}(i):...
What you asking about is [mathematical induction][1] theorem, more known as mathematical induction principle. It states, that $$\begin{cases}{} P(n_0) \text{ true} & \\ (\forall n \geqslant n_0)\big(P(n)\Rightarrow P(n+1)\big) & \end{cases} \Rightarrow (\forall n\geqslant n_0)P(n) $$ verbally it means, that fo...
For $1\ge p_1 \ge \dots \ge p_n \ge 0$, and for $i\in[n]$ draw $k$ iid binary strings with $m$ length: $$X_{i,1},\dots,X_{i,k}\stackrel{iid}{\sim} \text{Bernoulli}(p_i)^m.$$ Viewing these binary strings as integers, define their ranks as $$\text{rank}(i,s):=\#\{j\in[n]:X_{j,s}\ge X_{i,s}\}, \qquad \text{MinRank}(i):...
A [linear-feedback shift register][1] (LFSR) is a terrible PRNG(*), but (with correct selection of feedback taps) it seems to meet all your qualifications. A LFSR can run extremely fast -- faster than standard natural binary counters. > Is there one that, before it cycles, will generate each possible > number i...
Sure. Pick a [block cipher](https://en.wikipedia.org/wiki/Block_cipher) (i.e., [pseudorandom permutation](https://en.wikipedia.org/wiki/Pseudorandom_permutation)), $E_K$, and a random key for it, $K$. Let $x_i=E_K(i)$. Then this has the properties you are looking for.
Given a set B and B’s superset A, if B is missing 1 number (let’s say B’) but don’t know which number it is, how to find that number? That is, \ B’ = B \ {y}, for some missing element y \ B = A \ {x}, for some elements x \ I’d like to know {y} So far, my thought is:\ xor all numbers in A = C \ C xor B = missi...
>Let P be the complexity class of languages decidable by Turing machines running in polynomial time. Say a prefix $s$ of a string $x$ is an L prefix if $|s|\ge |x|/2$. For a language $A$, let $LP(A)$ be the language of all L prefixes of strings in $A$. Show that $P$ is not closed under $LP(\cdot )$ unless $P=NP$, where...
Show that P is not closed under an operation
|complexity-theory|turing-machines|strings|
Huffman coding follows a bottom-up approach where as Shannon-Fano coding is top-down. Is that contrast similar to dynamic programming versus greedy algorithm (dynamic programming always give optimal solution whereas greedy algorithm is sub-optimal)? If yes why is Huffman called greedy?
Is Huffman coding dynamic programming
|dynamic-programming|greedy-algorithms|huffman-coding|
Huffman coding follows a bottom-up approach where as Shannon-Fano coding is top-down. Is that contrast similar to dynamic programming versus greedy algorithm (dynamic programming always give optimal solution whereas greedy algorithm is sub-optimal)? If yes why is Huffman called greedy? Why greedy algorithm can also be ...
> dynamic programming always give optimal solution whereas greedy algorithm is sub-optimal Not True. There are problems where even a greedy approach would result in an optimal solution(Fractional knapsack, Minimum cost spanning tree, etc). **An algorithm is said to be greedy if at every step it chooses a best candid...
The same question was asked at https://mathoverflow.net/questions/426969/average-and-max-hitting-time-to-a-specific-vertex and for convenience, I reproduce the answer I just wrote there. Perhaps one of these copies will be removed eventually. **Notation:** Let $G=(V,E)$ be an undirected simple graph of $n$ node...
The *period* of a PRNG is how many random numbers you can generate before the sequence starts to repeat. If you don't mind using lower-quality PRNG algorithms, some classic ones (which fell out of favour for good reason) have short periods; for example **an LCG can be constructed with any period you want, even for non...
Let me put a few ideas about the chess, to start from: - The main course of any game is to win. So assuming that both players will do best to prevent win or loose is against the logic of game and asks different question. **What will be the complexity of not getting winner?** instead of **Complexity of winning?** ...
{"Voters":[{"Id":755,"DisplayName":"D.W."}],"SiteSpecificCloseReasonIds":[]}
This is an addendum to the answer by Yuval Filmus. Indeed $\phi(n)=\Theta(n)$, and the upper bound is explained in that answer. I don't understand the argument for the lower bound given there, but a simpler graph will yield the required bound. Let $G$ consist of a clique of $n-1$ vertices, where one of them, say $x$, i...
In fact, the cover time can be estimated up to a constant factor deterministically in polynomial time. See Ding, Jian, James R. Lee, and Yuval Peres. "Cover times, blanket times, and majorizing measures." In Proceedings of the forty-third annual ACM symposium on Theory of computing, pp. 61-70. 2011.
The cover time is at most the maximal hitting time multiplied by the harmonic number $1+\ldots+1/n$. This is the Mathews bound, see, e.g., Section 11.2 in [1]. In fact, the cover time can be estimated up to a constant factor deterministically in polynomial time. See [2], where the history of the problem is also dis...
PRNGs (pseudorandom number generators) generally have a bit length for the binary numbers they generate (e.g. 32 bits, 64 bits). This is the universe of their possible numbers. It seems that they typically cycle when they reach their 2^bitlen number. Is there one that, before it cycles, will generate each possibl...
PRNGs (pseudorandom number generators) generally have a bit length for the binary numbers they generate (e.g. 32 bits, 64 bits). This is the universe of their possible numbers. It seems that they typically cycle when they reach their 2^bitlen number. Is there one that, before it cycles, will generate each possibl...
PRNGs (pseudorandom number generators) generally have a bit length for the binary numbers they generate (e.g. 32 bits, 64 bits). This is the universe of their possible numbers. It seems that they typically cycle when they reach their 2^bitlen number. Is there one that, before it cycles, will generate each possibl...
null