instruction stringlengths 0 29.8k ⌀ |
|---|
A representation where the state space is all paths to the goal is completely unusable. It blows up the state space exponentially large. And it loses the structure that algorithms like A* make good use of. |
null |
A representation where the state space is all paths to the goal is completely unusable. It blows up the state space exponentially large. And it loses the structure that algorithms like A* make good use of.
Yes, search in a graph *is* an optimization problem, and you could certainly view it from that perspective, a... |
null |
I saw a question on an old exam in my university course of DSA and I am not sure if the question is far too easy or if I am missing something.
The question is :
> Given an array A that consists of N integers such that for any $1 < i \leq N$ the following properties holds :
>* $| A[i] - A[i-1] | \leq 1$
>* $... |
Finding an element within an array that satisfies some rule |
|arrays| |
I saw a question on an old exam in my university course of DSA and I am not sure if the question is far too easy or if I am missing something.
The question is :
> Given an array A that consists of N integers such that for any $1 < i \leq N$ the following properties holds :
>* $| A[i] - A[i-1] | \leq 1$
>* $... |
null |
null |
null |
If $L$ is regular , then FirstHalves or $Half(L)$ is also regular.
**Algorithm:**
1. Design $DFA, M$ of language $L$
2. Find the reversal of $DFA$ ,$M$ , say $N.$
3. Traverse $M$ for one transition (for given $\Sigma$ ) and $N$ for one transition (for $\Sigma$ ) , and repeat the process.
4. If We r... |
If $L$ is regular , then FirstHalves or $Half(L)$ is also regular.
**Algorithm:**
1. Design $DFA, M$ of language $L$
2. Find the reversal of $DFA$ ,$M$ , say $N.$
3. Traverse $M$ for one transition (for given $\Sigma$ ) and $N$ for one transition (for $\Sigma$ ) , and repeat the process.
4. If We r... |
If $L$ is regular , then FirstHalves or $Half(L)$ is also regular.
**Algorithm:**
1. Design $DFA, M$ of language $L$
2. Find the reversal of $DFA$ ,$M$ , say $N.$
3. Traverse $M$ for one transition (for given $\Sigma$ ) and $N$ for one transition (for $\Sigma$ ) , and repeat the process.
4. If We r... |
If $L$ is regular , then FirstHalves or $Half(L)$ is also regular.
**Algorithm:**
1. Design $DFA, M$ of language $L$
2. Find the reversal of $DFA$ ,$M$ , say $N.$
3. Traverse $M$ for one transition (for given $\Sigma$ ) and $N$ for one transition (for $\Sigma$ ) , and repeat the process.
4. If We r... |
Yes, this problem is polynomial-time solvable.
Let $A$ be the input numbers and let $S = \mathrm{sum}(A)$ be its sum.
Let $T_1 = 0.49S$, $T_2 = 0.51 S$ be the target sum range. Let $\epsilon = 0.02$ so that $T_2 - T_1 = \epsilon S$.
Define $A_1 = \{ a \in A \mid a \geq \epsilon S \}$ to be *large* items and $A_2... |
What is the difference between time complexity of SLR(k) and SLR(1)? and also what about LALR(k) and LALR(1)?
How can I calculate time complexity of parsers? I think time complexity of LR(k) is O(n) but I'm not sure there is a relation between LR(k) and SLR(k) or LALR(k)!
|
What is the time complexity of SLR and LALR parsers? |
|time-complexity|compilers|parsers|lr-k| |
They all run linear time with regards to input length ($O(n)$). The different algorithms have different memory trade offs for making it easier to write grammar for. That is not all grammars that work for LR(1) work for SLR for example. However LR(1) uses more memory than SLR which used to be a problem, but not really a... |
I understand the basics of the 0-1 problem and its solution.
I have a variant of it that I'm trying to solve in a decent way and I'm struggling on it, mostly because of the 0-weighted items.
These are the rules:
- I have k finite sets of items. Each item has a weight and a value.
- I must take exactly one ite... |
They all run linear time with regards to input length ($O(n)$). The different algorithms have different memory trade offs for making it easier to write grammar for. That is not all grammars that work for LR(1) work for SLR for example. However LR(1) uses more memory than SLR which used to be a problem, but not really a... |
They all run linear time with regards to input length ($O(n)$). The different algorithms have different memory trade offs for making it easier to write grammar for. That is not all grammars that work for LR(1) work for SLR for example. However LR(1) uses more memory than SLR which used to be a problem, but not really a... |
They all run linear time with regards to input length ($O(n)$). The different algorithms have different memory trade offs for making it easier to write grammar for. That is not all grammars that work for LR(1) work for SLR for example. However LR(1) uses more memory than SLR which used to be a problem, but not really a... |
Lets say a[1] = 1, a[N = 1000] = 2, and z = 450. The first array element that could equal z is a[450], and the last one is a[552]. Since 450 ≤ 552, there could be a solution.
So you have reduced the range. Now check the values a[450] and a[552]. Either one of them is equal to z, or you can reduce the range again. No... |
Yes, you can.
For instance: with language $L = \{a^nb^n \mid n\ge0\}$
and mapping $h(\epsilon)=\epsilon, h(a)=a, h(b)=a$ (which I think is what you meant to write), $h(L) = (aa)^*$.
What is more: [*every* context-free language on a single-symbol alphabet is regular][1], so a mapping that maps every symbol to the... |
I don't know a prior result on this particular problem. However, I can show this problem is NP-hard by reducing the hitting set problem.
Suppose we are given an instance of the hitting set problem as a bipartite graph $(U, V, E)$. Let $n = |U|$.
The reduction adds $n$ new vertices to both sides $U' = U \cup \{u_{... |
It is just a matter of whether you take the values before or after the shift.
[![enter image description here][2]][2]
[![enter image description here][3]][3]
[1]: https://i.stack.imgur.com/hbMLf.png
[2]: https://i.stack.imgur.com/oISVi.png |
It is just a matter of whether you take the values before or after the shift.
[![enter image description here][1]][1]
[![enter image description here][2]][2]
[1]: https://i.stack.imgur.com/CqMJT.png
[2]: https://i.stack.imgur.com/oISVi.png |
Prove/disprove the following claim:
If $L\in RL$ then $\{x|\exists y ~~s.t~~ xyx^R \in L\} \in RL$
I think that this is true, and my intuition is by using $L_{pq}$ s.t:
For every $(p,q)\in Q\times Q$ define $L_{pq}=\{w|\delta'(p,w)=q\}$.
Then by using $L_{pq}○L_{q,q'}○(L_{pq})^R$ and taking the union of all... |
If $L$ is regular then $\{x|\exists y s.t xyx^R \in L\}$ is regular |
|formal-languages|regular-languages|automata|finite-automata|context-free| |
If $L$ is regular , then FirstHalves or $Half(L)$ is also regular.
**Algorithm:**
1. Design $DFA, M$ of language $L$
2. Find the reversal of $DFA$ ,$M$ , say $N.$
3. Traverse $M$ for one transition (for given $\Sigma$ ) and $N$ for one transition (for $\Sigma$ ) , and repeat the process.
4. If We r... |
If $L$ is regular then $\{x~|~\exists y ~~s.t~~ xyx^R \in L\}$ is regular |
Prove/disprove the following claim:
If $L\in RL$ then $\{x~|~\exists y ~~s.t~~ xyx^R \in L\} \in RL$
I think that this is true, and my intuition is by using $L_{pq}$ s.t:
For every $(p,q)\in Q\times Q$ define $L_{pq}=\{w|\delta'(p,w)=q\}$.
Then by using $L_{pq}○L_{q,q'}○(L_{pq})^R$ and taking the union of a... |
An infinite union of regular languages is not necessarily regular. Indeed, every language is an infinite union of regular languages: $$ L = \bigcup_{x \in L} \{x\}. $$
So your proof idea doesn't quite work.
---
Start with an automaton for $L$, with states $Q$, initial state $q_0$, final states $F$, and transitio... |
I have to find a CFG for the given expression:
$L = \{a^wb^xc^yd^z | w + x = y + z\}$
This is what I've tried so far:
S -> aSd | B | ϵ
B -> bBc | ϵ
It works for expressions like: aabcdd, abbbcccd
However, using my grammar I wouldn'd be able to generate strings like: aaaacddd, abbddd, which, I assume,... |
Find a Context-Free Grammar for $L = \{a^wb^xc^yd^z | w + x = y + z\}$ |
|formal-languages|context-free|formal-grammars| |
Start with an automaton for $L$, with states $Q$, initial state $q_0$, final states $F$, and transition function $\delta$. Construct a new automaton whose set of states is $Q \times 2^Q$. After reading a word $x$, the new automaton should be at state
$$
\langle \delta(q_0,x), \{q : \delta(q,x^R) \in F\} \rangle.
$$
... |
A regular expression can be developed from the following finite state machine for at most 2 **A**s and at least 3 **B**s by using all possible paths separate by |, and using * where their is a loop edge.
[![Finite State Machine][1]][1]
[1]: https://i.stack.imgur.com/CV3xU.png |
The constraints on $w, x,y, z$ are not given, I choose everyone $\geq 0.$
The strings could be equal $a$ and equal $d,$ equal $b$ and equal $c,$ equal $b$ and equal $d,$ equal $a$ and equal $c $ etc.(since $w, x,y, z\geq 0.$)
$S\to aSd$
$X\to aXc$
$Y\to bYd$
$Z\to bZc$
Now from start symbol we cou... |
The proposed approach by @gnasher729 is true. Maybe the following commands clarify it.
Let L=1 and U=N for the lower and upper range of the search area in array A.
1. Repeat the following commands:
2. If L>U then Z does not exist in array A and terminate.
3. If Z==A[L] or Z==A[U] then we found Z and terminate.
4... |
The constraints on $w, x,y, z$ are not given, I choose everyone $\geq 0.$
The strings could be equal $a$ and equal $d,$ equal $b$ and equal $c,$ equal $b$ and equal $d,$ equal $a$ and equal $c $ etc.(since $w, x,y, z\geq 0.$)
$S\to aSd$
$X\to aXc$
$Y\to bYd$
$Z\to bZc$
Now from start symbol we cou... |
A regular expression can be developed from the following finite state machine for at most 2 **A**s and at least 3 **B**s by using all possible paths separate by |, and using * where their is a loop edge.
[![Finite State Machine][1]][1]
Resulting regex: ```AABBBB*|ABABBB*|ABBABB*|ABBBAB*|BAABBB*|BABABB*|BABBAB*|BB... |
A regular expression can be developed from the following finite state machine for at most 2 **A**s and at least 3 **B**s by using all possible paths separate by |, and using * where their is a loop edge.
[![Finite State Machine][1]][1]
Resulting regex: ```AABBBB*|ABABBB*|ABBABB*|ABBBAB*|BAABBB*|BABABB*|BABBAB*|BB... |
A regular expression can be developed from the following finite state machine for at most 2 **A**s and at least 3 **B**s by using all possible paths separate by |, and using * where their is a loop edge.
[![Finite State Machine][1]][1]
Resulting regex: ```AABBBB*|ABABBB*|ABBABB*|ABBBAB*|ABBBB*AB*|BAABBB*|BABABB*|... |
null |
The question is:
There are 219 matches on a table and 2 players , each player can take 1,3 or 4 matches off the table , winner is who takes the last match.
is there a winning strategy that guarantees for the **second player** to always win? .
I can't think of a way to calculate without having to do the recursion m... |
Dynamic programming , Matches game and winning strategies |
|algorithms|dynamic-programming| |
The constraints on $w, x,y, z$ are not given, I choose everyone $\geq 0.$
The strings could be equal $a$ and equal $d,$ equal $b$ and equal $c,$ equal $b$ and equal $d,$ equal $a$ and equal $c $ etc.(since $w, x,y, z\geq 0.$)
$S\to aSd$
$X\to aXc$
$Y\to bYd$
$Z\to bZc$
Now from start symbol we cou... |
**For directed graph :-**
Suppose there are 7 vertices {0,1,2,3,4,5,6} and consider the worst case where every vertex is connected to every other vertex =>
No of edges required to reach from x to y vertices is as follows :
(6->6) 6 to 6 =0
(5->6) 5 to 6 =1
(4->6) 4 to 6 = (4 to 5 -> 6) + (4 to 6->6) = ... |
I am solving basic questions about **Recursive** and **Recursively-Enumerable** languages. I know that base on the below theorem, to prove that a language is **RE** we should define an **Enumeration Procedure** for it.
> A language is recursively enumerable if and only if there is an
> enumeration procedure for it.... |
Let $L$ be a finite language. Show that then $L^+$ is recursively enumerable. Suggest an enumeration procedure for $L^+$ |
|automata|recursively-enumerable| |
When the number of matches is of the form 7$k$ or 7$k$ + 2, the second player wins; otherwise, the first player wins. I cannot claim to have an intuition of why this should be so, but once you write the program and notice the pattern, it is easy to prove by induction.
```c++
#include <stdio.h>
#define MAX_N 100
... |
This is called *Enumerative Coding* and was introduced by Tom Cover. Consider a word $W$ that is $n$ bits long, where the one bits are in locations $x_k, \ldots, x_1$ with $x_k>x_{k-1}>\cdots>x_1$ and the locations are labelled from $0$ to $n-1.$
The position of this word in the lexicographic ordering of all word... |
>Prove that the following language is context-free by giving a context-free grammar that generates the language: $A = \{a \in \{0,1\}^* : \text{ no character in an even position is a 0 or no character in an odd position is a 1}\}$, where the first position is position 1. For instance, $01110, 01010$ are both in $A.$
... |
First start with a related task: enumerate all (finite) sequences of natural numbers. We will devide those sequences into a sequence of finite sets, and then we can enumerate all sequences by taking the sets one after another and enumerating the items in those sets.
For every sequence of numbers $(x_1, x_2, \dots, x... |
null |
First start with a related task: enumerate all (finite) sequences of natural numbers. We will devide those sequences into a sequence of finite sets, and then we can enumerate all sequences by taking the sets one after another and enumerating the items in those sets.
Note that we *cannot* enumerate first all sequence... |
If $L$ is regular , then FirstHalves or $Half(L)$ is also regular.
**Algorithm:**
1. Design $DFA, M$ of language $L$
2. Find the reversal of $DFA$ ,$M$ , say $N.$
3. Traverse $M$ for one transition (for given $\Sigma$ ) and $N$ for one transition (for $\Sigma$ ) , and repeat the process.
4. If We r... |
>Suppose o is a map on strings to strings. For every language R, we let $o(R) := \{o(x) : x \in R\}$. If o(R) is a regular language for every regular language R, then prove or disprove that the language $\{xc o(x) :x \in A\}$ is context-free, where A is a regular language and c is a symbol not in the alphabet of A, $\S... |
Prove or disprove that $\{xc o(x) :x \in A\}$ is context-free, where A is a regular language |
|formal-languages|regular-languages|finite-automata|context-free|formal-grammars| |
Suppose $x$ is Godel's number of some formula. Predicate $\operatorname{P}(\operatorname{f}(x))$ is true only when the number of functions is equal to the number of predicates in that formula.
Prove that $\operatorname{P}(\operatorname{f}(x))$ is primitive recursive.
My Godel Numbering system is
$$G(\forall)=1... |
Prove a Predicate is Primitive Recursive |
|complexity-theory|computability|logic|recurrence-relation|primitive-recursion| |
null |
Let $p,q$ be two states of a DFA, such that $p\equiv_kq$ and $p\equiv_{k+1}q$.
Does it mean that $p\equiv q$ ?
I don't think so, because if the minimization algorithm can continue, they might be separate at a later state, am I correct?
Thanks! |
If two states of a DFA are k-equivalent and k+1 equivalent |
|formal-languages|regular-languages|automata|finite-automata|context-free| |
null |
Your operation is very general, and in its generality your conjecture is not true.
For instance take for $o$ the identity, then we get the simple example $o(\{a,b\}^*) = \{wcw\mid w\in \{a,b\}^*\}$ which is not context-free.
Your examples show that a better conjecture would be that instead $\{ x c\, o(x^R)\mid x\... |
ANTLR handles direct left recursive grammar via a technic they call an oracle. You can find their paper to learn all about it.
Basically the parser remembers if it had just parsed the current non-terminal being parsed. If it hasn't, then the left recursive choice gets ignored. Otherwise the left recursive branch is ... |
ANTLR handles direct left recursive grammar via a technic they call an oracle. You can find their paper to learn all about it.
Basically the parser remembers if it had just parsed the current non-terminal being parsed. If it hasn't, then the left recursive choice gets ignored. Otherwise the left recursive branch is ... |
{"Voters":[{"Id":112114,"DisplayName":"Fred Jefferson"}]} |
>Let $w$ and $x$ be two binary strings. Show that the Hamming distance of $wx$ and $xw$ cannot be 1.
I think one approach is a proof by contradiction. I was thinking of explicitly writing out $w = w_1\cdots w_k$ and $x = x_1\cdots x_n$, and proceeding with a case-based argument. Let $i$ be the unique index where the... |
Show that the Hamming distance of $wx$ and $xw$ cannot be 1 |
|formal-languages|formal-grammars|strings|hamming-distance| |
{"Voters":[{"Id":112114,"DisplayName":"Fred Jefferson"}]} |
>For two equal-length binary strings x and y, let $d(x,y)$ denote the Hamming distance. Prove or disprove: there exists a positive integer k such that the language $\{x2y : |x| = |y|, x\in A, d(x,y) = k\}$ is context-free for some infinite regular language A over the alphabet $\{0,1\}$.
I think the statement is ... |
is $\{x2y : |x| = |y|, x\in A, d(x,y) = k\}$ context-free for some infinite regular language A |
|formal-languages|context-free|formal-grammars| |
>Is there a non-context free language A over the alphabet $\{0,1\}$ such that $A1 := \{a1 : a\in A\}$ is context free?
I was thinking of the language $A = \{0^n 1^{n-1} : n > 0\}.$ Unfortunately, this language seems to satisfy the pumping lemma for context-free languages: pick any $n\ge 2.$ Then for all $w\in A, |w|... |
is there a non-context free language A such that A1 is context free? |
|formal-languages|context-free|formal-grammars| |
>Is there a non-context free language A over the alphabet $\{0,1\}$ such that $A1 := \{a1 : a\in A\}$ is context free?
I was thinking of the language $A = \{0^n 1^{n-1} : n > 0\}.$ Unfortunately, this language is context-free. I’m not sure if one might be able to show that context-free languages are closed under the... |
$w$ and $x$ are binary strings.
Clearly $|wx|=|xw|$ and $|wx|_0=|xw|_0$. Suppose $wx$ and $xw$ differ only at position $i$, so that $(wx)[i]\ne(xw)[i]$, $(wx)[1..i-1]=(xw)[1..i-1]$, and $(wx)[i+1..n+k]=(xw)[i+1..n+k]$.
Wolog, assume $(wx)[i]$ is $1$, and thus $(xw)[i]$ is $0$. Now,
$$\begin{align}|wx|_0 &= ... |
Y$w$ and $x$ are binary strings.
Clearly $|wx|=|xw|$ and $|wx|_0=|xw|_0$. Suppose $wx$ and $xw$ differ only at position $i$, so that $(wx)[i]\ne(xw)[i]$, $(wx)[1..i-1]=(xw)[1..i-1]$, and $(wx)[i+1..n+k]=(xw)[i+1..n+k]$.
Wolog, assume $(wx)[i]$ is $1$, and thus $(xw)[i]$ is $0$. Now,
$$\begin{align}|wx|_0 &=... |
I proposed a better approximation algorithm for vertex cover problem (a [1.999999-approximation][1] algorithm by solving a well-known SDP model and a randomized procedure). It is not published, yet. But, I am sure that it is true (I am grateful if anyone identify any potential issues).
To clarify the main topics of ... |
null |
I am studying the book "Parametrized Algorithms" and it suggests a bounded search tree algorithm for k-Vertex Cover. Basically we look at a vertex v and say :
*Either v will cover it's incident edges or it has to be it's neighbors $N(V)$ so either $v$ or $N(v)$ will end up in the cover*.
That's 2 choices , we b... |
Bounded search tree: k-Vertex cover with $\Delta(G) = 2$ |
|algorithms|algorithm-analysis|parameterized-complexity| |
Once all vertices have degree $<=2$ you don't branch on them - you just apply a standard polynomial time algorithm to solve it.
Since your graph consists of a disjoint set of cycles and line graphs, the min vertex cover for components which are line graphs would be $⌊C/2⌋$ and $⌈C/2⌉$ for cycles where $C$ is the siz... |
null |
I came here to ask for help with a two-tape Turing machine for the following language.
$L = \{ a^{n^2} | n \ge 0 \}$
I tried following the advice on this site: [Turing machine that accepts L={an2|n≥1}
[duplicate]][1]
[1]: https://cs.stackexchange.com/questions/118739/turing-machine-that-accepts-l-an2-n-%... |
Help with two-tape Turing Machine for $L = \{ a^{n^2} | n \ge 0 \}$ - clarification needed |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.