instruction
stringlengths
0
29.8k
⌀
Consider the regular expressions - $(1+01)^*(0+\epsilon)$ - $(1^*011^*)^*(0+\epsilon) + 1^*(0+\epsilon)$, where $\epsilon$ is the empty string. I need to determine if these expressions are equivalent. Intuitively it seems they are equivalent because they seem to generate the languages of strings without ...
Proving Equivalence of Two Regular Expressions
|formal-languages|regular-languages|finite-automata|regular-expressions|proof-techniques|
null
How to show $f: \mathbb{N} \to\mathbb{N}$ with $f(x)=4x$ where $x$ is in the set of natural numbers $x\in\mathbb{N}$) is Turing Computable? My guess is obviously *there is a finite number of operations needed to reach a solution meaning it is Turing computable*. Not sure how to prove this though! Can someone pl...
I recently submitted a paper where in part of the paper I derived a bound on a function (note it is an upper bound). The benefit of the bound is that it is much less complex to compute in contrast to the actual value of the function. So, the bound can be used as a cost for optimization instead of the actual value of th...
How to evaluate the tightness of a bound on a function?
|optimization|proof-techniques|lower-bounds|upper-bound|
null
Interesting question! ------ For ease of analysis, assume the numbers in the given array are distinct. This assumption does not change the asymptotic nature of problems at hand. WLOG, assume the given array is selected uniformly from all permutations of $0, 1,\cdots, n-1$. ------ **Lemma 1.** Given arra...
Number of Inversions found in Selection sort vs Exchange sort
To evaluate tightness of a bound on a function, you need to find both the upper and lower bounds. Finding an upper bound on the function is good but it leaves the possibility that the actual function might be asymptotically better than the computed upper bound. For example, suppose the actual function is $f(x) = n +...
You can easily reduce the problem to [circulation problem][1] that is solvable in polynomial time. [1]: https://en.wikipedia.org/wiki/Circulation_problem
I'm looking at a problem similar to an assignment problem. There are both agents and tasks. Each agent has a list of tasks they are able to do, and cannot do any task not within that list (note that agents do not have a preference for what task they do, only a list of tasks they are able to do). A task can be assign...
The problem is $\mathsf{NP}$-hard via a reduction from [Exact Cover by 3-sets problem][1]. Let $(X,F)$ be an instance of Exact Cover by 3-sets problem. Then, the set $X$ corresponds to agents and the set $F$ corresponds to tasks. Each task will have an upper and lower bound of $3$. You can easily prove the following st...
Here's another perspective. Less mathematical, but I think also insightful. Using a fabulous [sort visualizer](https://xosh.org/VisualizingSorts/sorting.html#IYZwngdgxgBAZgV2gFwJYHsIwKIA8oAWwEA5gKYDK6ATsgBTDXUA0MAJtcAO4CUMA3gCgYUTCGQwsAXhiNqAOgA2ZUsgIBuYXBow6yiaikAGdTFQAeCKdQBqG3yEx4OvWQkArKalPvLPuw7CTqhwunIA2u4AujDmsk...
I'm not sure exactly what you're trying to achieve (formulating the goal precisely seems tricky or unclear to me), but you might be interested in reading about "fair exchange" in the cryptographic literature. See, e.g., https://crypto.stackexchange.com/q/8333/351. The short version you're likely to find is that there...
Here's another perspective. Less mathematical, but I think also insightful. Using a fabulous [sort visualizer](https://xosh.org/VisualizingSorts/sorting.html#IYZwngdgxgBAZgV2gFwJYHsIwKIA8oAWwEA5gKYDK6ATsgBTDXUA0MAJtcAO4CUMA3gCgYUTCGQwsAXhiNqAOgA2ZUsgIBuYXBow6yiaikAGdTFQAeCKdQBqG3yEx4OvWQkArKalPvLPuw7CTqhwunIA2u4AujDmsk...
Interesting question! Indeed, the expected numbers are quadratic and linearithmic respectively. #### Assumptions For ease of analysis, assume the numbers in the given array are distinct. This assumption does not change the asymptotic nature of problems at hand. WLOG, assume the given array is selected uniform...
null
Say that a Context Free Grammar is red when it accepts every word of length 3 that begins with a, and extremely red when it accepts every word that begins with a. Is redness decidable? or Semi decidable? will the algorithm go into an infinite loop when presented with certain invalid statements? Also what about ex...
Decidability of a context free Grammar
|untagged|
null
"Redness" is decidable, because the alphabet of a context-free grammar is finite (by definition), and therefore the set of strings exactly three characters long starting with `a` is also finite. So you only need to try every string in that finite set. "Extreme redness" is very different. Here, the question is whethe...
The question will be hard to understand without an example, so let's given an example first: Let's say I have a 2 dimensional concave polytope, defined by a **circular sequence** of its vertices: $(0,0), (1, 4), (2, 0) (1, 1), (0, 0)$ [![The concave polytope][1]][1] Let's say I wanted to find the polytope I...
Getting a "sub-polytope" of a concave d-dimensional polytope, given some one dimensional inequality
|computational-geometry|linear-algebra|
null
(Note: this answer doesn't fully answer the question — I don't know whether the language is context-free — it merely addresses the question of whether it satisfies the pumping lemma, which was raised in the question and discussed in the comments, and is obviously relevant in that the language cannot be cont...
When $d>2$, I believe a sequence of vertices does not uniquely determine a non-convex polytope, so it looks to me like your representation has some issues and your 2D example is misleading. But assuming an appropriate representation of a (non-convex) polytope: If $d$ is not too large, the following works: Enumerate ...
(Note: this answer doesn't fully answer the question — I don't know whether the language is context-free — it merely addresses the question of whether it satisfies the pumping lemma, which was raised in the question and discussed in the comments, and is obviously relevant in that the language cannot be cont...
Interesting question! Indeed, the expected numbers are quadratic and linearithmic respectively. #### Assumptions For ease of analysis, assume the numbers in the given array are distinct. This assumption does not change the asymptotic nature of problems at hand. WLOG, assume the given array is selected uniform...
Conjecture: a half of a pairing context-free language must be a regular language
null
I am reading about pumping lemma: For any regular language L, there exists an integer n, such that for all x ∈ L with |x| ≥ n, there exists u, v, w ∈ Σ∗, such that x = uvw, and (1) |uv| ≤ n (2) |v| ≥ 1 (3) for all i ≥ 0: u(v)^iw ∈ L My question is, what exactly is the "pumping length" n here. When provin...
What exactly is pumping length in pumping lemma?
|finite-automata|pumping-lemma|theory|
When using the pumping lemma, you do assume such $p$ exists, assuming that the language is regular. This $p$, no matter what it is, should exists since it is the number of states for the DFA of the language. You do not however need to know its exact value, it must exists if the language is regular. You can read it ...
Let $N_h$ denote the minimum number of nodes in a height-balanced tree of height $h$. Given a height-balanced tree of height $h$, without loss of generality assume the left child of the root has height $h-1$. The right child must have height $h-1$ or $h-2$, and to get the smallest possible values (the worst-case), as...
The first result that will be useful is $\ln x^r = r \ln x$, where $\ln$ is the natural logarithm. When the base of the logarithm changes to a different number $a$, the logarithm can be rewritten as a ratio natural logarithms: $\log_a x = \frac{\ln x}{\ln a}$. This can be proved by starting with $y=\log_a x$, or its e...
The pumping length $n$ must be assumed to be arbitrary - you can't fix it to be a particular value. The pumping lemma is used to prove that a given language is nonregular, and it is a proof by contradiction. The idea behind proofs that use the pumping lemma is as follows. To prove a given language $L$ is nonregul...
Let $N_h$ denote the minimum number of nodes in a height-balanced tree of height $h$. Given a height-balanced tree of height $h$, without loss of generality assume the left child of the root has height $h-1$. The right child must have height $h-1$ or $h-2$, and to get the smallest possible values (the worst-case), as...
In the lecture it was shown that $N_h \geq 2N_{h-2}$. You can obtain the bound of $2^{h/2} $ for this recurrence by continued expansion of the r.h.s., also called unrolling the recurrence. E.g. : $N_h \geq 2N_{h-2} = 2 * (2N_{h-4}) = 2*(2*(2N_{h-6})) = 2(2(2(...(2N_0)...)))$. This expansion will continue until yo...
Can anyone please help me solve this better than $O(|a-b| \cdot n)$? Given an array of both negative and positive numbers, we want to find the maximum sum of the elements in contiguous subarray having a length **between** $a$ and $b$. Example Input: 8 1 2 -1 13 -2 5 13 -5 2 2 Output: 18 Here a = ...
> An accountant in a big firm would like to find the median of the > salaries of all employees. The data they received is a list of size n > containing the tuples $\left\{n_{i\ },f_{i\ }\right\}_{i=1}^{n}$, > where the number $s_i$ is the salary and the integer $f_i$ is the > number of employees that got salary $s_...
Finding Median value given a tuple (value, frequency) in O(n) worst case time complexity
|time-complexity|sorting|selection-problem|
$L_1 ,L_2$ are regular language. We form a new language $L_{12}$ as follows: $$L_{12}=\left \{ w_1\cdot w_2\mid w_1\in L_1\land w_2\in L_2\land |w_1|=|w_2| \right \}$$ In this exercise I am not given any alphabet and I'm required to build a PDA for $L_{12}$. But by definition $M=\left \{Q,\sum,\Gamma,\delta ,q_0,\d...
So I am studying PTAS algorithms. For a maximazation problem the difinition says that an algorithm that has value A , is a ptas if : $A \geq opt(1-\epsilon) \; ,\forall \epsilon > 0$ (and I guess also $\epsilon < 1$ (?) ) Obviously for any constant $c>0 : opt(1-\epsilon) \geq \frac{opt}{2}(1-c\epsilon)$ S...
Is $\frac{opt}{2}(1-c\epsilon)$ for some constant c >0 considered a PTAS?
|complexity-theory|algorithm-analysis|approximation|
If the pairs are given ordered by increasing salary, it suffices to compute the prefix sum of the frequencies $F_k:=\sum_{i=1}^k f_k$ and find the sum closest to the half of the total. If the pairs are not ordered, you are stuck.
So I am studying PTAS algorithms. For a maximazation problem the difinition says that an algorithm that has value A , is a ptas if : $A \geq opt(1-\epsilon) \; ,\forall \epsilon > 0$ (and I guess also $\epsilon < 1$ (?) ) Obviously for any constant $c>0 : opt(1-\epsilon) \geq \frac{opt}{c}(1-\epsilon)$ So...
Is $\frac{opt}{c}(1-\epsilon)$ for some constant c >0 considered a PTAS?
I was looking at an example of grammar from the website: [grammer example][1] which is as follows: S → aB / bA S → aS / bAA / a B → bS / aBB / b I believe they forgot to write: A -> a Next, we are going to derive the string: aaabbabbba I did it by myself and found the following: Left derivatio...
When is a grammar ambiguous or When is a grammar not ambiguous?
|automata|context-free|formal-grammars|theory|derivation|
**Pumping Lemma** : For any regular language $\mathbb{L}$, there exists an integer $n$, such that for all $x\in \mathbb{L}$ with $|x|\geq n$, there exists $u, v, w \in \Sigma^*$, such that $x = uvw$, and 1. $|uv| \leq n$ 2. $|v| > 0$ 3. $uv^iw ∈ \mathbb{L} \space\forall i\geq0$ My question is, what exactly...
|regular-languages|automata|finite-automata|regular-expressions|pumping-lemma|
null
> An accountant in a big firm would like to find the median of the > salaries of all employees. The data they received is a list of size n > containing the tuples $\left\{s_{i\ },f_{i\ }\right\}_{i=1}^{n}$, > where the number $s_i$ is the salary and the integer $f_i$ is the > number of employees that got salary $s_...
I have a set of line segments (say 1000 of them) and a query point. I want to find the segment which is the closest in the Euclidean sense (if the point does not project on the segment I accept two options: 1) just ignore the segment - infinite distance - or 2) consider the distance to the closest endpoint). Preprocess...
Nearest line-segment to a query point
|computational-geometry|nearest-neighbour|
Nearest line-segment to a query point or conversely
I have a set of line segments (say 1000 of them) and a query point. I want to find the segment which is the closest in the Euclidean sense (if the point does not project on the segment I accept two options: 1) just ignore the segment - infinite distance - or 2) consider the distance to the closest endpoint). Preprocess...
The condition is trivially true for $\epsilon < 1$, so you don't need to require that. That said, the condition $A \ge \frac{\text{opt}}{c} \cdot (1-\varepsilon) \; \forall \varepsilon >0$ is equivalent to $A \ge \text{opt} \cdot (1-\varepsilon') \; \forall \varepsilon' > \frac{c-1}{c}$ since we can relate $\vareps...
null
The condition is trivially true for $\epsilon \ge 1$, so you don't need to require that. That said, the condition $A \ge \frac{\text{opt}}{c} \cdot (1-\varepsilon) \; \forall \varepsilon >0$ is equivalent to $A \ge \text{opt} \cdot (1-\varepsilon') \; \forall \varepsilon' > \frac{c-1}{c}$ since we can relate $\vare...
null
This is a problem that I have found from Introduction to automata theory, languages and computation. PDA, P=({q0,q1,q2,q3,f)},{a, b},{Z0,A,B},δ,q0,Z0,{f}) has the following rules defining δ: δ(q0,a,Z0)=(q1,AAZ0) δ(q0,b,Z0)=(q2,BZ0) δ(q0,∈,Z0)=(f,∈) δ(q1,a,A)=(q1,AAA) ...
Informal description of a PDA
|pushdown-automata|
I'm trying to solve following modified knapsack problem using dynamic programming. **What we know:** - Total number of items - Item weight, value and type - Knapsack capacity **Aims** - Find Maximum weight of knapsack - List taken Items **Constraints** - Only one item of each type can b...
Solve modified knapsack problem using dynamic programming
|dynamic-programming|knapsack-problems|java|
I think you can still use the linear time selection algorithm (medians of medians) here. Let's call this algorithm $Select$. Recall that the algorithm has 3 phases: 1. Group by 5 and select median of group 2. Choose partition element $m$, by applying $Select$ to find the median of the medians. 3. Partition the ele...
I think you can still use the linear time selection algorithm (medians of medians) here. Let's call this algorithm $Select$. Recall that the algorithm has 3 phases: 1. Group by 5 and select median of group 2. Choose partition element $m$, by applying $Select$ to find the median of the medians. 3. Partition the ele...
I think you can still use the linear time selection algorithm (medians of medians) here. Let's call this algorithm $Select$. Recall that the algorithm has 3 phases: 1. Group by 5 and select median of group 2. Choose partition element $m$, by applying $Select$ to find the median of the medians. 3. Partition the ele...
I think you can still use the linear time selection algorithm (medians of medians) here. Let's call this algorithm $Select$. Recall that the algorithm has 3 phases: 1. Group by 5 and select median of group 2. Choose partition element $m$, by applying $Select$ to find the median of the medians. 3. Partition the ele...
That grammar as presented (with the addition of the production $A\to a$) is certainly ambiguous, regardless of what the site you copied it from says. Your work demonstrates that, and it can easily be verified using a parser generator or CFG analyzer. A grammar is ambiguous if it has more than one leftmost derivation...
I think you can still use the linear time selection algorithm (medians of medians) here. Let's call this algorithm $Select$ and let the median position be $m$, which is initially equal to $n/2$.Recall that the algorithm has 3 phases: 1. Group by 5 and select median of group 2. Choose partition element $p$, by apply...
This answer explains an $O(n)$-time algorithm. ### Basic Ideas The ideas are classic. - "Sum of the elements in subarray" -- prefix sums. - "Length between `a`and `b`" -- window of size `b-a+1`. - "Maximum" -- maximum queue for the window We will compute the array of prefix sums `prefix_sums` first. T...
I think you can still use the linear time selection algorithm (median of medians) here. Let's call this algorithm $Select$ and let the median position be $m$, which is initially equal to $n/2$.Recall that the algorithm has 3 phases: 1. Group by 5 and select median of group 2. Choose partition element $p$, by applyi...
The pumping length $n$ must be assumed to be arbitrary - you can't fix it to be a particular value. The pumping lemma is used to prove that a given language is nonregular, and it is a proof by contradiction. The idea behind proofs that use the pumping lemma is as follows. To prove a given language $L$ is nonregul...
That grammar as presented (with the addition of the production $A\to a$) is certainly ambiguous, regardless of what the site you copied it from says. Your work demonstrates that, and it can easily be verified using a parser generator or CFG analyzer. (See below for what they probably meant.) A grammar is ambiguous i...
I was watching video [*Lec 2 | MIT 6.046J / 18.410J Introduction to Algorithms (SMA 5503), Fall 2005*](https://youtu.be/whjt_N9uYFI?t=3859), where professor Erik Demaine said that $a^{\log_b n}$ is the same as $n^{\log_b a}$. Can someone please explain me why bringing "the $n$ downstairs" and "the $a$ upstairs" is poss...
Why is $a^{\log_b n}$ the same as $n^{\log_b a}$?
|asymptotics|
This is a problem that I have found from Introduction to automata theory, languages and computation. PDA, P=({q0,q1,q2,q3,f)},{a, b},{Z0,A,B},δ,q0,Z0,{f}) has the following rules defining δ: δ(q0,a,Z0)=(q1,AAZ0) δ(q0,b,Z0)=(q2,BZ0) δ(q0,∈,Z0)=(f,∈) δ(q1,a,A)=(q1,AAA) ...
Let $C \ge 1$ be the capacity of the knapsack and let $G_1, \dots,G_k$ be your groups, where each group is a non-empty collection of items, i.e., $G_i = \{ x^{(i)}_1, x^{(i)}_2, \dots \}$. Groups are pairwise disjoint. Define $n= \sum_{i=1}^k |G_i|$ as the total number of items in the instance. For any item $x$, let...
Let $C \ge 1$ be the capacity of the knapsack and let $G_1, \dots,G_k$ be your groups, where each group is a non-empty collection of items, i.e., $G_i = \{ x^{(i)}_1, x^{(i)}_2, \dots \}$. Groups are pairwise disjoint. Define $n= \sum_{i=1}^k |G_i|$ as the total number of items in the instance. For any item $x$, let...
The "Pumping Length" "n" exists because you can write a finite automata that classifies all strings up to a fixed, finite length in any way it wants to. Your finite automata can have (in effect) a lookup table, and decide where each string goes (accepted or not accepted). But, you cannot make an infinite lookup t...
Hello I am struggling with proving a lemma, it goes as follows: Suppose we have a vector r = (r1....rn)^T where rj is either 0 or 1 which is selected uniformly at random with probability 1/2. Suppose now we have a n x n matrix called M (which has at least one non zero element). I need to prove that the Pr[Mr = 0]...
Randomized Algorithm Lemma
|algorithms|data-structures|randomized-algorithms|
So, I have asked this question at my university, and the answer I got was: 1. The model does not account for parallelism, only concurrency. 2. The model assumes that events are "instant" or "atomic". So no two events can occur at the same time because no two things ever happen at the same time (no "paralellism"), ...
This is a problem that I have found from *Introduction to automata theory, languages and computation* by John Hopcroft and Jeffrey Ullman. PDA P=({q0, q1, q2, q3, f)}, {a, b}, {Z0, A, B}, δ, q0, Z, {f}) has the following rules defining δ: δ(q0,a,Z)=(q1,AAZ) δ(q0,b,Z)=(q2,BZ) δ(q0,...
An exercise that asks for informal description of the language accepted by a specific PDA