instruction
stringlengths
0
29.8k
⌀
null
null
I have a flow question which I'm stumped on but seems like there should be an answer that I am not seeing. Consider a network with a start $s$ and an end $t$ and a bipartite graph $L \cup R$. $s$ is connected to all vertices in $L$ via edges with capacity $1$. All vertices in $R$ are connected to $t$ via edges with...
I have a flow question which I'm stumped on but seems like there should be an answer that I am not seeing. Consider a network with a start $s$ and an end $t$ and a bipartite graph $L \cup R$. $s$ is connected to all vertices in $L$ via edges with capacity $1$. All vertices in $R$ are connected to $t$ via edges with...
in his original paper "on computable numbers with an application to the entscheidungsproblem"[[1]](https://www.cs.virginia.edu/~robins/Turing_Paper_1936.pdf) Turing didn't have halting problem (see [[2]](https://www.researchgate.net/profile/Salvador-Lucas/publication/352559794_Did_Turing_Care_of_the_Halting_Problem/lin...
in his original paper "on computable numbers with an application to the entscheidungsproblem"[[1]](https://www.cs.virginia.edu/~robins/Turing_Paper_1936.pdf) Turing didn't have halting problem (see [[2]](https://www.researchgate.net/profile/Salvador-Lucas/publication/352559794_Did_Turing_Care_of_the_Halting_Problem/lin...
in his original paper "on computable numbers with an application to the entscheidungsproblem"[[1]](https://www.cs.virginia.edu/~robins/Turing_Paper_1936.pdf) Turing didn't have halting problem (see [[2]](https://www.researchgate.net/profile/Salvador-Lucas/publication/352559794_Did_Turing_Care_of_the_Halting_Problem/lin...
The question has been asked many times for [regular PDA](https://cs.stackexchange.com/search?q=minimize+PDA), but my question is about **deterministic** PDA. For tools like lexer generators, where occasionally a counter or a stack would be needed to lex languages with string interpolation or other constructs, the qu...
Is there an algorithm for minimizing DPDA in terms of states? Is it even computable?
|optimization|pushdown-automata|
null
To expand on Nathaniel's answer, you can number the subsets efficiently using the [combinatorial number system][1]. In short, say your subset is $[c_1, c_2,\ldots, c_k]$ (where $k=60$). Compute $N = \binom{c_1}{1}+\binom{c_2}{2}+\ldots+\binom{c_k}{k}$. (note that we use the convention that $\binom{n}{m} = 0$ for $n<...
null
Consider an array A[1..n] that first increases up to some point p then it decreases until some point q and then increases again. That is A[k] < A[k + 1] for all k in [1..p] and [q..n] and A[k] > A[k + 1] if p < k < q. Suppose we are searching for the element A[p] or the index p, whats the fastest possible algorith...
For a given integer exponent $e$, I want to identify all factors of an integer $n$ which are of the form $p^{e}$, where $p$ is a prime. So, for $e = 1$, this is equivalent to getting the unique prime factors, for $e = 2$ it's extracting all of the square factors, etc. Currently, I am doing this by iterating over the...
Fast identification of prime power factors?
|primes|factoring|
In the worst case, this is probably about as hard as [factoring](https://en.wikipedia.org/wiki/Integer_factorization). As far as we know, factoring squarefree integers is about as hard as factoring integers in general, so for the case $e=1$, this is likely to be about as hard as factoring. And, of course, it isn't an...
Let's say I have a 60 set of numbers from **0-100,000** so like `[81, 98, 115, 189, 254, ... , 97866, 98441, 99671]` all unique and progressively increasing. Would it be mathematically possible to compress this sequence by 80-90%? so far I've tried gzip which only compresses at 50% and other algorithms the best one I f...
Let's say I have a 60 set of numbers from **0-100,000** so like `[81, 98, 115, 189, 254, ... , 97866, 98441, 99671]` all unique and progressively increasing. Would it be mathematically possible to compress this sequence by 80-90%? so far I've tried gzip which only compresses at 50% and other algorithms the best one I f...
Is there an algorithm for minimizing a deterministic PDA in terms of states? Is it even computable? I know that it is not possible to minimize a [PDA](https://cs.stackexchange.com/q/37461/755) in general, but my question is about *deterministic* PDA. For tools like lexer generators, where occasionally a counter o...
Minimizing DPDA
If you don’t want to do anything more difficult than trial division: For the exponent 1 this is practically the same as factoring. For an exponent e >= 2: You can use trial division by primes 2, 3, 5 etc and when you find a prime factor, you check if it is a high enough exponent, and remove the factor from the ...
In the worst case, this is probably about as hard as [factoring](https://en.wikipedia.org/wiki/Integer_factorization). As far as we know, factoring squarefree integers is about as hard as factoring integers in general, so for the case $e=1$, this is likely to be about as hard as factoring. And, of course, it isn't an...
null
In the worst case, this is probably about as hard as [factoring](https://en.wikipedia.org/wiki/Integer_factorization). As far as we know, factoring squarefree integers is about as hard as factoring integers in general, so for the case $e=1$, this is likely to be about as hard as factoring. And, of course, it isn't an...
Question I was asked: Does it make a difference if I say "The worst case run time is $O(n^2)$ vs the worst case run time is $\theta(n^2)$?" To me, the only difference is that when we say $O(n^2)$, the function may also be $O(n)$, we do not know. But when we say $\theta(n^2)$, we know for a fact the function is $O(n^...
Is Big-Theta a more accurate description of worst case run time than Big-O?
|asymptotics|runtime-analysis|big-o-notation|notation|
I was reading through Sipser's "Introduction to the Theory of Computation" and in it, he states that all computational models with unrestricted access to unlimited memory are "equivalent in power, so long as they satisfy reasonable requirements". He gives the example of an requirement which is that only a finite amount...
"Reasonable" requirements for a computation model to be equivalent in power to a Turing machine
|turing-machines|computability|computation-models|
I have the following slide in my notes and I'm having trouble understanding how the three assertions are equivalent. I understand to a degree how the 2nd and 3rd assertions are equivalent, but the equivalence between the 1st and 3rd as well as the 1st and 2nd isn't really explained well here. Am I missing something? Is...
Logical Consequence - Equivalent Assertions
|satisfiability|artificial-intelligence|sets|propositional-logic|equality|
in his original paper "on computable numbers with an application to the entscheidungsproblem"[[1]](https://www.cs.virginia.edu/~robins/Turing_Paper_1936.pdf) Turing didn't have halting problem (see [[2]](https://www.researchgate.net/profile/Salvador-Lucas/publication/352559794_Did_Turing_Care_of_the_Halting_Problem/lin...
null
null
null
I'm looking for a data structure to help me solve the following problems: Given a set of points (x,y), find the subset of points where if you order by one dimension, the other dimension is strictly increasing. Be able to keep this subset consistent through updates of the data set. E.g. order the dataset first in...
Data structure for tracking ordered sub-sequences of data
|data-structures|sorting|
Yes. Your understanding is correct on all points!
I'm looking for a data structure to help me solve the following problems: EDIT: This describes a skyline query. Given a set of points (x,y), find the subset of points where if you order strictly increasing by one dimension, we only take points that are also strictly increasing in the other dimension. We must b...
{"OriginalQuestionIds":[93061],"Voters":[{"Id":755,"DisplayName":"D.W."}]}
What is known about the languages: $$S_f = \{ [M] \ | \ \exists{x} \ \text{s.t.} \\ M \ \text{accepts} \ x \ \text{in} \ f(|[M]|) \ \text{steps}, \\ \ |x| \leq f(|[M]|) \}$$ I used to think that in order to check if a string $[M]$ is in $S_f$ you cannot avoid simulating $M$ on all possible $x$ whose length is les...
What is known about the languages: $$S_f = \{ [M] \ | \ \exists{x} \ \text{s.t.} \\ M \ \text{accepts} \ x \ \text{in} \ f(|[M]|) \ \text{steps}, \\ \ |x| \leq f(|[M]|) \}$$ I used to think that in order to check whether a string $[M]$ is in $S_f$ you cannot avoid simulating $M$ on all possible $x$ whose length i...
Your reasoning is wrong because you assert something without proof. You just assert that the only way to do it is to try all $x$, but there is no justification given for this assertion, and we don't know whether that assertion is true. Just because you can only think of one way to solve a problem, doesn't mean it is ...
[DOI: 10.3390/e24070884](https://www.mdpi.com/1099-4300/24/7/884) provides pseudocode for computing the assembly index of an object. It is written as recursive algorithm, which might be fine. But I would like to implement an iterative version of this in Python which has a recursion depth limit. Although this limit can ...
Iterative algorithm for assembly index?
|algorithms|graphs|search-algorithms|recursion|partial-order|
null
O(f(n)) is also used when there is no simple function that your runtime is close to. For example: Find the smallest prime factor of n by trial division, finishing when a factor is found: There are O(n^1/2) tests if you divide by all integers up to the square root of n. But for even n there is only one test, and similar...
{"OriginalQuestionIds":[67897],"Voters":[{"Id":755,"DisplayName":"D.W.","BindingReason":{"GoldTagBadge":"algorithms"}}]}
null
Yes they all are equivalent. Using **standard rules of inference i.e. Modus Ponen, Modus Tollen, Hypothetical syllogism and Fallacies**, which are just ways to infer logical consequences of a set of formulas, you can resolve a set of clauses(formulas) to get a resolvent. In this case using the rules of inference, one n...
After some arguments why you can't generally do better: What if $A[n] \lt A[1]$? Every element smaller $A[1]$ is to the right of $p$, every element greater $A[n]$ is to the left of $q$.
null
in his original paper "on computable numbers with an application to the entscheidungsproblem"[[1]](https://www.cs.virginia.edu/~robins/Turing_Paper_1936.pdf) Turing didn't have halting problem (see [[2]](https://www.researchgate.net/profile/Salvador-Lucas/publication/352559794_Did_Turing_Care_of_the_Halting_Problem/lin...
Yes they all are equivalent. Using **standard rules of inference i.e. Modus Ponen, Modus Tollen, Hypothetical syllogism and Fallacies**, which are just ways to infer logical consequences of a set of formulas, you can resolve a set of clauses(formulas) to get a resolvent. In this case using the rules of inference, one n...
I have a problem in a Data Structures course I am taking. The question is as follows: Given a number of variables $x_1,\dots,x_n$ and given $m$ equality and inequality constraints (in total $m$ constraints). Find if there exists a valid assignment that satisfies all constraints in $O((m+n)\log^*n)$ and in $O(m+n)$. ...
Algorithm to find if there exists an assignment such that all equality and inequality constraints are satisfied
|algorithms|data-structures|
Your algorithm may fail in some situations. For example, $x_1=x_3$, $x_2=x_3$ and $x_1\not=x_2$. ------ When you "go over all of $x_i$ equality constraints", for each constraint $x_i=x_j$ (or $x_j=x_i$), check first whether $x_j$ is not $null$ first. If $x_j$ is not $null$ and not equal to $i$, return "that ther...
in his original paper "on computable numbers with an application to the entscheidungsproblem"[[1]](https://www.cs.virginia.edu/~robins/Turing_Paper_1936.pdf) Turing didn't have halting problem (see [[2]](https://www.researchgate.net/profile/Salvador-Lucas/publication/352559794_Did_Turing_Care_of_the_Halting_Problem/lin...
I have a pathfinding project and I want to use Kruskal's algorithm as a maze generator. I am using a rank-based disjoint set data structure to detect cycles, which seems to be the standard way. However, the mazes that I generate cannot be solved. Which leads me to think that there might be something wrong with my im...
Implementation check for Kruskal's algorithm used for maze generation
|shortest-path|maze|
Kruskal's algorithm iterates through edges, not through vertices. I think it would be better if it looked like: ``` init_walls() //m by n grid of walls W = set of all walls p = 0 //counting the number of passages created While p < m × n - 1 (u, v) = random_wall() if find(u) ≠ find(v) ...
Your algorithm may fail in some situations. For example, $x_1=x_2$, $x_2=x_4$, $x_3=x_4$, and $x_1\not=x_2$. 1. $i=1$, $x_1\leftarrow1$, $x_2\leftarrow1$. 2. $i=2$, $x_4\leftarrow1$. 3. $i=3$, $x_3\leftarrow3$, $x_4\leftarrow3$. 4. $i=4$, $x_2\leftarrow3$. At the end, we find that the only inequality $x_1\not...
Your algorithm may fail in some situations. For example, $x_1=x_2$, $x_2=x_4$, $x_3=x_4$, and $x_1\not=x_2$. 1. $i=1$, $x_1\leftarrow1$, $x_2\leftarrow1$. 2. $i=2$, $x_4\leftarrow1$. 3. $i=3$, $x_3\leftarrow3$, $x_4\leftarrow3$. 4. $i=4$, $x_2\leftarrow3$. At the end, the only inequality $x_1\not=x_2$ is sati...
Your algorithm may fail in some situations. For example, $x_1=x_2$, $x_2=x_4$, $x_3=x_4$, and $x_1\not=x_2$. 1. $i=1$, $x_1\leftarrow1$, $x_2\leftarrow1$. 2. $i=2$, $x_4\leftarrow1$. 3. $i=3$, $x_3\leftarrow3$, $x_4\leftarrow3$. 4. $i=4$, $x_2\leftarrow3$. At the end, the only inequality $x_1\not=x_2$ is sati...
null
To complement John L.'s $O((m+n)\log^*n))$ solution, here is a simple $O(n+m)$ time solution: Construct the graph $G$ (as an adjacency list structure) whose vertices correspond to your variables and edges correspond to equality constraints. Compute the connected components of this graph and a an array which to each ...
A straightforward reduction follows from Fowler, Paterson, and Tanimoto "[Optimal packing and covering in the plane are np-complete][1]" 1981. The details are in the paper. Summarized: To transform 3-SAT into this problem fill a large grid with -1 values, then place large positive valued cells in specific locations....
null
null
Roots of unity are trivial to find numerically--just evaluate $sin$ and $cos$ to whatever precision you require. But suppose (because it's true) that I want exact algebraic representations for symbolic manipulation. Well, I could cheat and use polar form, and store exact algebraic representations of the magnitude an...
Algorithm for nth roots of unity in symbolic radical form?
|algorithms|computer-algebra|
null
null
null
I'm trying to understand _Complexity of the hamiltonian cycle in regular graph problem_ [1]: I don't understand this part: > Lemma 2.11: HC-3-regular-(n-even) is NP-complete > > The result is obvious since the number of edges of a 3-regular graph is (3/2) n. I don't understand what is the relation of the num...
null
Recently, my girlfriend and I were trying to get out of the house, when I encountered a phenomenon which I thought might be analogous to a tradeoff in concurrent systems. Here's the real world setup. ### Processes - `Process A`: Girlfriend orders coffee on phone. - `Process B`: Girlfriend gets ready at apartme...
Trading time for work; does this concurrency phenomenon have a name?
|parallel-computing|concurrency|process-scheduling|
in his original paper "on computable numbers with an application to the entscheidungsproblem"[[1]](https://www.cs.virginia.edu/~robins/Turing_Paper_1936.pdf) Turing didn't have halting problem (see [[2]](https://www.researchgate.net/profile/Salvador-Lucas/publication/352559794_Did_Turing_Care_of_the_Halting_Problem/lin...
I'm trying to understand _Complexity of the hamiltonian cycle in regular graph problem_ [1]: I don't understand this part: > Lemma 2.11: HC-3-regular-(n-even) is NP-complete > > The result is obvious since the number of edges of a 3-regular graph is (3/2) n. I don't understand what is the relation of the num...
The difference is in the Gen for these Analyses. Gen(VBE) : gen VBE ([x = e ;] l ) = AExp(e) gen VBE ([while (b)  …  ] l ) = AExp(b) gen VBE ([if (b)  …  ] l ) = AExp(b) gen VBE ([…  ] l ) = ∅ Gen(AE) : gen AE ([x = e ;] l ) = {a’ ∈ AExp(e) | x not in vars(a’  ) } gen AE ([while (b)  …  ] l ) = AExp(b) g...
The difference is in the Gen for these Analyses. Gen(VBE) : gen VBE ([x = e ;] l ) = AExp(e) gen VBE ([while (b)  …  ] l ) = AExp(b) gen VBE ([if (b)  …  ] l ) = AExp(b) gen VBE ([…  ] l ) = ∅ Gen(AE) : gen AE ([x = e ;] l ) = {a’ ∈ AExp(e) | x not in vars(a’  ) } gen AE ([while (b)  …  ] l ) = AExp(b...
The difference is in the Gen for these Analyses. Gen(VBE) : gen VBE ([x = e ;] l ) = AExp(e) gen VBE ([while (b)  …  ] l ) = AExp(b) gen VBE ([if (b)  …  ] l ) = AExp(b) gen VBE ([…  ] l ) = ∅ Gen(AE) : gen AE ([x = e ;] l ) = {a’ ∈ AExp(e) | x not in vars(a’  ) } gen AE ([while (b)  …  ] l ) ...
null
null
null
I've seen some questions regarding the regularity of prefix language of non-regular languages (for examples, [here](https://cs.stackexchange.com/questions/98112/non-regular-language-whose-prefix-language-is-regular) and [here](https://cs.stackexchange.com/questions/117078/example-of-non-regular-context-free-language-l-...
Non-regular language whow prefix language is not the whole set of words
|formal-languages|regular-languages|regular-expressions|
If there are no further rules, then there is a simple solution. In any existing example double all symbols in each string. That is, change the symbols $0$ and $1$ by the pairs $00$ and $11$. Formally that is an homomorphism. Now the resulting language has no longer all strings as prefix. It also does not change cont...