instruction
stringlengths
0
29.8k
⌀
null
I don't see any problem with your first grammar and bison doesn't complain on the rendering I've done of it. I (and bison) see one conflict in your second grammar (which doesn't describe the same language as the first BTW). After having seen `id id id` with a pending `^`, you don't know if your last `id` and the `^`...
null
I'm pretty sure I've found an algorithm that does not rely on number theory or cycle theory. Note that there are a few details to work out (possibly tomorrow), but I'm quite confident they will work out. I handwave as I'm supposed to be sleeping, not because I'm trying to hide problems :) Let `A` be the first array,...
Let $L \subseteq \Sigma^*$ a regular language and $\qquad \displaystyle L(z) = \sum\limits_{n \leq 0} |L_n|z^n$ its [generating function](https://en.wikipedia.org/wiki/Chomsky%E2%80%93Sch%C3%BCtzenberger_theorem), where $L_n = L \cap \Sigma^n$ and so $|L_n|=s_L(n)$. It is known that $L(z)$ is [*rational*](http...
Let $L \subseteq \Sigma^*$ a regular language and $\qquad \displaystyle L(z) = \sum\limits_{n \leq 0} |L_n|z^n$ its [generating function](https://en.wikipedia.org/wiki/Chomsky%E2%80%93Sch%C3%BCtzenberger_theorem), where $L_n = L \cap \Sigma^n$ and so $|L_n|=s_L(n)$. It is known that $L(z)$ is [*rational*](http...
Let's apply Branch and Bound to [Knapsack][1], hopefully this will make the concept clear to you. We have $n$ items, labelled $1$ through to $n$. $v_i$ is the value of the $i$th item, and $w_i$ its weight. We try to fit them in a knapsack that can contain up to $T$ weight in total, and we try to maximize the sum of ...
When testing a set of numbers, if the sum of the subset is run through an equation where the solution is zero, or any integer value, is this still considered a subset-sum problem? ie. set={ −7, −3, −2, 5, 8} eq=f(x)=-3+x ; solution when f(x)=0 Answer where x is the subset sum of { -3,-2,8 }
Subset Sum Requirements
|complexity-theory|
It depends on the form of $f$. If $f(x) = x$, then it is identical to subset-sum. If $f(x) = 0$, then it is a trivial problem with an $O(1)$ solution: return $true$. You can possibly define $f$ in other ways to make the question more or less difficult, as well.
|algorithms|time-complexity|graphs|
The language is regular. **Hint:** [cast out nines](http://en.wikipedia.org/wiki/Casting_out_nines) ---- ### Proof idea For $a=9$ and $b < 9$, >! build an automaton with $9$ states labeled $0$ through $8$. $0$ is the initial state, and the one final state is $b$. From state $s$, on digit $d$, transition ...
> **Possible Duplicate:** > [Language of the values of an affine function](http://cs.stackexchange.com/questions/640/language-of-the-values-of-an-affine-function) <!-- End of automatically inserted text --> Let $C_n = \{x\mid x \text{ is a binary number that is a multiple of } n\}$. Show that for each $n$, the la...
{"OriginalQuestionIds":[640],"Voters":[{"Id":157,"DisplayName":"Ran G."},{"Id":41,"DisplayName":"Kaveh"},{"Id":92,"DisplayName":"Alex ten Brink"},{"Id":69,"DisplayName":"Patrick87"},{"Id":39,"DisplayName":"Gilles"}]}
It sounds like you want a cost-sensitive (cost-aware, [budgeted)][1] optimization technique. Minimizing two values (e.g. the solution of your objective and the cost of operations on $x$ and $y$) is a [multicriteria optimization problem][2], and those tend to be very hard to solve. A common approach is to specify a budg...
It depends on the form of $f$. If $f(x) = x$, then it is identical to subset-sum. If $f(x) = 0$, then it is a trivial problem with an $O(1)$ solution: return $true$. You can possibly define $f$ in other ways to make the question more or less difficult, as well. See below a mini-complexity zoo corresponding to differ...
null
[WalkSAT and GSAT](http://en.wikipedia.org/wiki/WalkSAT) are well-known and simple local search algorithms for solving the Boolean satisfiability problem. The pseudocode for the GSAT algorithm is copied from the question [Implementing the GSAT algorithm - How to select which literal to flip?](http://cs.stackexchange.co...
Supporting data structures for SAT local search
|algorithms|data-structures|satisfiability|sat|
Let $L \subseteq \Sigma^*$ a regular language and $\qquad \displaystyle L(z) = \sum\limits_{n \geq 0} |L_n|z^n$ its [generating function](https://en.wikipedia.org/wiki/Chomsky%E2%80%93Sch%C3%BCtzenberger_theorem), where $L_n = L \cap \Sigma^n$ and so $|L_n|=s_L(n)$. It is known that $L(z)$ is [*rational*](http...
When testing a set of numbers, if the sum of the subset is run through an equation where the solution is zero, or any integer value, is this still considered a subset-sum problem? I.e. $$S=\{ −7, −3, −2, 5, 8\}$$ find a subset $X$ such that if $\bar x=\sum_{x\in X}x$ then $f(\bar x)=0$, for various functions ...
Yes, this is still [subset sum problem](https://en.wikipedia.org/wiki/Subset_sum_problem), but instead of finding a subset whose sum is $0$, you are required to have a sum that equals something else (in your example it 3, in general it is $f^{-1}(0)$, which might be a set of numbers if $f$ is [many to one](https://en.w...
Consider the following problem. > Given a set $S$ of integers, a function $f : \mathbb{Z} \to \mathbb{Z}$ and $k \in \mathbb{Z}$, decide wether there is $X \subseteq S$ such that $f\left(\sum_{x\in X}x\right)=k$. Is this still considered a [subset-sum problem](https://en.wikipedia.org/wiki/Subset_sum)? For in...
Yes, this is still [subset sum problem](https://en.wikipedia.org/wiki/Subset_sum_problem), but instead of finding a subset whose sum is $0$, you are required to have a sum that equals something else (in your example it 3, in general it is $f^{-1}(0)$, which might be a set of numbers if $f$ is [many to one](https://en.w...
It depends on the form of $f$. If $f(x) = x$, then it is identical to subset-sum. If $f(x) = 0$, then it is a trivial problem with an $O(1)$ solution: return $true$. You can possibly define $f$ in other ways to make the question more or less difficult, as well. See below a mini-complexity zoo corresponding to differ...
|algorithms|data-structures|satisfiability|
Assume we have a simple language that exists of the terms: - true - false - if $t_1,t_2,t_3$ are terms then so is if $t_1$ then $t_2$ else $t_3$ Now assume the following logical evaluation rules: - if true then $t_2$ else $t_3 \rightarrow t_2$ [E-IfTrue] - if false then $t_2$ else $t_3 \rightarrow t_3$...
Question about (simple) structural inductive type theoretical proof
|proof-techniques|type-theory|inductive-datatypes|
null
Assume we have a simple language that consists of the terms: - $\mathtt{true}$ - $\mathtt{false}$ - if $t_1,t_2,t_3$ are terms then so is $\mathtt{if}\: t_1 \:\mathtt{then}\: t_2 \:\mathtt{else}\: t_3$ Now assume the following logical evaluation rules: $$ \begin{gather*} \dfrac{} {\mathtt{if}\: \m...
Confluence proof for a simple rewriting system
|proof-techniques|semantics|term-rewriting|
Okay, so let's consider the case that $r = \mathtt{if}\: t_1 \:\mathtt{then}\: t_2 \:\mathtt{else}\: t_3$, $s$ has been derived by applying the E-If rule and $t$ has been derived by applying the E-Funny rule: So $s = \mathtt{if}\: t'_1 \:\mathtt{then}\: t_2 \:\mathtt{else}\: t_3$ where $t_1 \rightarrow t'_1$ and $t = \...
Let $G=(V,E)$ be some complete, weighted, undirected graph. We construct a second graph $G'=(V, E')$ by adding edges one by one from $E$ to $E'$. We add $\Theta(|V|)$ edges to $G'$ in total. Every time we add one edge $(u,v)$ to $E'$, we consider the shortest distances between all pairs in $(V, E')$ and $(V, E' \cup...
How many shortest distances change when adding an edge to a graph?
|algorithms|graphs|shortest-path|
Let $G=(V,E)$ be some complete, weighted, undirected graph. We construct a second graph $G'=(V, E')$ by adding edges one by one from $E$ to $E'$. We add $\Theta(|V|)$ edges to $G'$ in total. Every time we add one edge $(u,v)$ to $E'$, we consider the shortest distances between all pairs in $(V, E')$ and $(V, E' \cup...
Let $G=(V,E)$ be some complete, weighted, undirected graph. We construct a second graph $G'=(V, E')$ by adding edges one by one from $E$ to $E'$. We add $\Theta(|V|)$ edges to $G'$ in total. Every time we add one edge $(u,v)$ to $E'$, we consider the shortest distances between all pairs in $(V, E')$ and $(V, E' \cup...
Unfortunately, even adding one edge can cause $\Theta(|V|^2)$ many shortest paths to change. Consider the following linear chain with $n+1$ nodes and viciously chosen weights: ![example][1] <sup>[[source](http://verrech.net/sefiles/cs_1062.tikz)]</sup> Clearly, the edges could have been added in order of their...
Unfortunately, even adding one edge can cause $\Theta(|V|^2)$ many shortest paths to change. Consider the following linear chain with $n+1$ nodes and viciously chosen weights: ![example][1] <sup>[[source](http://verrech.net/sefiles/cs_1062.tikz)]</sup> Clearly, the edges could have been added in order of their...
After reading several sources I'm still confused about user and kernel level threads. In particular: "threads can exist at both the user level and the kernel level" what is the difference between the user level and kernel level?
What is the difference between the user level and kernel level?
|operating-systems|os-kernel|
After reading several sources I'm still confused about user and kernel level threads. In particular: > Threads can exist at both the user level and the kernel level What is the difference between the user level and kernel level?
null
null
One of the roles of a multitasking operating system kernel is [scheduling](http://en.wikipedia.org/wiki/Scheduling_%28computing%29): determining which thread of execution to execute when. So such a kernel has some notion of [thread](http://en.wikipedia.org/wiki/Thread_%28computer_science%29) or [process](http://en.wiki...
After reading several sources I'm still confused about user- and kernel-level threads. In particular: > Threads can exist at both the user level and the kernel level What is the difference between the user level and kernel level?
What is the difference between user-level threads and kernel-level threads?
|operating-systems|concurrency|os-kernel|
Okay, so let's consider the case that $r = \mathtt{if}\: t_1 \:\mathtt{then}\: t_2 \:\mathtt{else}\: t_3$, $s$ has been derived by applying the E-If rule and $t$ has been derived by applying the E-Funny rule: So $s = \mathtt{if}\: t'_1 \:\mathtt{then}\: t_2 \:\mathtt{else}\: t_3$ where $t_1 \rightarrow t'_1$ and $t = \...
A little terminology may help if you want to look this up: these rules are [*rewriting* rules](http://en.wikipedia.org/wiki/Rewriting), they have nothing to do with type systems¹. The property you're trying to prove is called *[confluence](http://en.wikipedia.org/wiki/Confluence_%28abstract_rewriting%29)*; more specifi...
null
null
For example, in this picture(alpha-beta pruning): ![enter image description here][1] [1]: https://i.stack.imgur.com/NmKIO.jpg When traverse first node 3, it will get B's max value is 3. After traverse 12 and 8, it will make sure B's max value is 3. But why B's min value is also 3? What is the usag...
What's the usage of min value on min-max tree?
|data-structures|
|logic|semantics|proof-techniques|term-rewriting|
You can get arbitrary difficult problems depending on your $f$. Let $A$ be a language. Define $f$ as follows: $$f(x)= \begin{cases} 0 & x\in A \\ 1 & o.w. \\\end{cases}$$ Consider set $S=\{x\}$. There is a non-empty subset $X\subseteq S$ s.t. $f(\Sigma_{x\in X} x) = 0$ iff $x \in A$. Without putting a comple...
Prove or disprove that an algorithm which in O(n) time finds 3 indices i, j, and k such that i < j < k and array[i] < array[j] < array[k] can exist. This isn't a homework question, I saw it on a programming forum framed as “try to implement such an algorithm.” I suspect that it's impossible, after various experiment...
Prove or disprove that an algorithm which in O(n) time finds 3 indices
|untagged|
null
There is an O(n) time algorithm, which uses O(n) space. First, traverse the array left to right maintaining a stack and a bitvector which tells you for each element, if there is an element greater than it and to the right of it. Initially the stack is empty and the bitvector contains all zeroes. Each time yo...
There is an O(n) time algorithm, which uses O(n) space. First, traverse the array left to right maintaining a stack and a bitvector which tells you for each element, if there is an element greater than it and to the right of it. Initially the stack is empty and the bitvector contains all zeroes. Each time yo...
There is an $O(n)$ time algorithm, which uses $O(n)$ space. First, traverse the array left to right maintaining a stack and an auxiliary array which tells you for each element, the index of an element greater than it and to the right of it. Initially the stack is empty and the aux array contains all $-1$s. Eac...
There is an $O(n)$ time algorithm, which uses $O(n)$ space. First, traverse the array left to right maintaining a stack and an auxiliary array which tells you for each element, the index of an element greater than it and to the right of it. Initially the stack is empty and the aux array contains all $-1$s. Eac...
|algorithms|
There is an $O(n)$ time algorithm, which uses $O(n)$ space. First, traverse the array left to right maintaining a stack and an auxiliary array which tells you for each element, the index of an element greater than it and to the right of it. Initially the stack is empty and the aux array contains all $-1$s. Eac...
This is variation of [Longest increasing subsequence][1] problem, you can define two array: > > M[j] — stores the position k of the smallest value X[k] such that there is an > increasing subsequence of length j ending at X[k] on the > range k ≤ i (note we have j ≤ k ≤ i here, because j represents...
For example, in this picture(alpha-beta pruning): ![enter image description here][1] [1]: https://i.stack.imgur.com/NmKIO.jpg When traverse first node 3, it will get B's max value is 3. After traverse 12 and 8, it will make sure B's max value is 3. But why B's min value is also 3? What is the usag...
null
Consider the following linear chain with $n+1$ nodes, $n$ edges and viciously chosen weights: ![example][1] <sup>[[source](http://verrech.net/sefiles/cs_1062.tikz)]</sup> Clearly, the edges could have been added in order of their weights and there are $n \in \mathcal{O}(|V|)$ of them. Adding the dashed edge (w...
Let $G=(V,E)$ be some complete, weighted, undirected graph. We construct a second graph $G'=(V, E')$ by adding edges one by one from $E$ to $E'$. We add $\Theta(|V|)$ edges to $G'$ in total. Every time we add one edge $(u,v)$ to $E'$, we consider the shortest distances between all pairs in $(V, E')$ and $(V, E' \cup...
I want to prove or disprove the existence of an algorithm which, given an array $A$ of integers, finds three indices $i, j$ and $k$ such that $i < j < k$ and $A[i] < A[j] < A[k]$ (or finds that there is no such triple) in linear time. This is not a homework question; I saw it on a programming forum framed as “try to...
Is there an algorithm which finds sorted subsequences of size three in O(n) time?
This is variation of [Longest increasing subsequence][1] problem; this is the solution presented on Wikipedia using two auxiliary arrays $M$ and $P$: > * $M[j]$ — stores the position $k$ of the smallest value $A[k]$ such that there is an increasing subsequence of length $j$ ending at $A[k]$ on the > range $k...
Consider [min-max trees](https://en.wikipedia.org/wiki/Min/max_kd-tree) where each node is marked with the minimum and maximum of keys in its subtree. For example, in this picture (alpha-beta pruning): ![enter image description here][1] [1]: https://i.stack.imgur.com/NmKIO.jpg When marking the the tree wit...
What use are the minimum values on min-max trees?
|data-structures|binary-trees|trees|
In other words, what advantages does Hybrid threading have over 1:1 and N:1 threading?
What is the purpose of M:N (Hybrid) threading?
|operating-systems|concurrency|os-kernel|
This is an expanded version of my answer from here http://cs.stackexchange.com/questions/1027/using-pumping-lemma-to-prove-language-is-not-regular since this is supposed to be a reference question. So, you think the pumping lemma looks complicated? Don't worry. Here's a slightly different take on it, which is hidd...
In other words, what advantages does [Hybrid threading](http://en.wikipedia.org/wiki/Thread_%28computer_science%29#M%3aN_.28Hybrid_threading.29) have over 1:1 (kernel only) and N:1 (user only) threading? <sub>This is a follow-up to http://cs.stackexchange.com/questions/1065/what-is-the-difference-between-user-level-...
I think hybrid threading is very similar to a [thread pool](http://en.wikipedia.org/wiki/Thread_pool_pattern). In thread pool, you are using $N$ kernel threads to execute $M$ “tasks”, where $M$ can be much higher than $N$. The advantage over using one thread for each task (kernel only threading) is that you consume...
I think hybrid threading is very similar to a [thread pool](http://en.wikipedia.org/wiki/Thread_pool_pattern). In thread pool, you are using $N$ kernel threads to execute $M$ “tasks”, where $M$ can be much higher than $N$. The advantage over using one thread for each task (kernel only threading) is that you consume...
This problem is taken from [interviewstreet.com][1] Given array of integers $Y=\{y_1,...,y_n\}$, we have n line segments such that endpoints of segment i are (i, 0) and (i, yi). Imagine that from the top of each segment a horizontal ray is shot to the left, and this ray stops when it touches another segment or it hi...
How to approach Vertical Sticks challenge
|untagged|
First off, the link in the question appears to be to a different data structure. A better link would be [this one][1]. This figure is used in the explanation of the alpha-beta pruning algorithm on a minimax tree. Alpha-beta pruning is a method used to prune parts of the minimax tree in an adversarial search problem. In...
It seems as though modern speech recognition (e.g., through Android, iOS phones) make use of grammar or sentence structure. (e.g., it might have a tough time distinguishing between "grammar" and "grandma" but can distinguish between "I'm going to see grandma" and "I'm reading a book on english grammar". (yes, I just tr...
When did commercial Speech Recognition first begin using grammar (sentence structure) for prediction?
|software-engineering|
First off, the link in the question appears to be to a different data structure. A better link would be [this one][1]. This figure (which is in fact correct) is used in the explanation of the alpha-beta pruning algorithm on a minimax tree. Alpha-beta pruning is a method used to prune parts of the minimax tree in an adv...