instruction stringlengths 0 29.8k ⌀ |
|---|
This answer explains an algorithm that finds the minimum number of edges in $O(n\log n)$ time. With more bookkeeping, the path of weight $k$ and that minimum number of edges can also be found in $O(n\log n)$ time.
#### Weight-Length Tree With Offsets
A "OT" will be the shorthand for a "balanced binary search tree... |
Consider this problem from [Jeff Erickson Algorithm][1]
that already in this site, there is a this post [about it][2] where it want us prove a lower bound for it.
The question is:
Suppose you are given an array $A[1 .. n]$ of integers, each of which may be positive, negative, or zero. A contiguous subarray $A[i... |
Greedy algorithm for postive interval covering |
|algorithms|greedy-algorithms| |
I read from this [post](https://cs.stackexchange.com/questions/144692/why-equality-is-decidable-for-regular-language-but-not-for-cfl) the term configuration space. I don't know the meaning of *configuration space*.
What is the exactly meaning of *configuration space?*
And why DFA's configuration space is finite... |
Why DFA's configuration space is finite and PDA configuration space is infinite? |
|finite-automata|pushdown-automata| |
There is a greedy algorithm. However, it is not as simple as people usually thought. Or, I could also say, it is not as complicated as people usually thought.
### A greedy algorithm
<!--
Compute the prefix sums $B[0..n]$ such that $B[0]=0$ and $B[i]=B[i-1]+a[i]$ for $i\ge1$. $B[i]$ is the sum of the first $i$ e... |
There is a greedy algorithm. However, it is not as simple as people think usually. Or, I could also say, it is much simpler than people think usually.
### A greedy algorithm
<!--
Compute the prefix sums $B[0..n]$ such that $B[0]=0$ and $B[i]=B[i-1]+a[i]$ for $i\ge1$. $B[i]$ is the sum of the first $i$ elements ... |
A configuration of a machine $M$ means the situation/setting of a machine at a particular moment while it is running. The configuration space of $M$ means all possible configurations of $M$.
More formally, given a DFA $D=(Q, \Sigma, \delta, q_0, F)$, a configuration of $D$ is the current state of $D$. So there are $... |
null |
Consider this problem from [Jeff Erickson's Algorithm book][1],
> Given a tree $T=(V,E)$ that each node has a reward, also given
> $k\in\mathbb{N}$. Our goal is to find maximum number of disjoint paths
> (note that a path cannot contains two children of the same node),
> such that sum of rewards of paths maximiz... |
largest number of disjoint paths with lenght k and maximum reward in a tree |
|algorithms| |
{"Voters":[{"Id":755,"DisplayName":"D.W."}],"SiteSpecificCloseReasonIds":[]} |
Suppose that $w$ is a well-formed parenthetical word of depth at most $d$. Then either $w = \epsilon$, or $d > 0$ and $w = (x)y$, where $x$ is a parenthetical word of depth at most $d-1$, and $y$ is a parenthetical word of depth at most $d$; furthermore, the decomposition is unique. |
Let $Different_{DFA,PDA} = \{<M_1,M_2> \vert \ M_1 \text{ is a DFA and } M_2 \text{ is a PDA where } L(M_1) \neq L(M_2)\}$, we want to show that this language is undecidable
Let $ALL_\text{CFG} = \{<G> | \text{ G is a CFG and } L(G) = Σ^*\}$, as we know this language is undecidable, hence its complement, ${\overli... |
I am trying to find a better way to find all leaf nodes in my undirected waypoint graph.
This is how I define a leaf node:
A leaf node is a node that is never part of a cycle and so has to meet one of these two criteria:
1) It has only one connection
Or
2) The node's total connections mine the total... |
Performant way to find all leaf nodes in a undirected graph |
|algorithms|graphs| |
To get the dual of a planar graph, each of the faces becomes a vertex. And then, two vertices in the dual graph are connected if they share a common face. My question is about planar graphs that have disconnected components. It's unclear to me how to define a face for these. As a simple example, consider the graph belo... |
Dual of a graph where the faces are unclear |
|graphs|duality| |
I am trying to find a better way to find all leaf nodes in my undirected waypoint graph.
This is how I define a leaf node:
A leaf node is a node that is never part of a cycle and so has to meet one of these two criteria:
1) It has only one connection
Or
2) The node's total connections minus the tota... |
I am trying to find a better way to find all leaf nodes in my undirected waypoint graph.
This is how I define a leaf node:
A leaf node is a node that is never part of a cycle and so has to meet one of these two criteria:
1) It has only one connection
Or
2) The node's total connections minus the tota... |
I am reading chapter 1 of Michael Sipser's "Theory of Computation" and in the section "Formation defination of NFA" he says the following:
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/5Sh84.png
3rd point of the above image is the point of interest in the post
According to a few... |
Is ε a part of alphabet or property of alphabet and NFA in FA |
|automata|finite-automata|computation-models|nondeterminism|theory| |
In the definition of $\Sigma_\epsilon$, $\epsilon$ is a letter (which must not belong to $\Sigma$).
Elsewhere, $\epsilon$ is the empty word.
To avoid confusion, you can use different symbols for the two different meanings, say use $\epsilon$ for the empty word and $\hat\epsilon$ for the letter of $\Sigma_\epsilo... |
Consider this problem from [Jeff Erickson's Algorithm book][1],
> Given a tree $T=(V,E)$ in which each node has a reward, and
> $k\in\mathbb{N}$, our goal is to find the maximum number of disjoint paths
> (note that a path cannot contains two children of the same node),
> such that sum of rewards of paths maximiz... |
Largest number of disjoint paths of length $k$ and maximum reward in a tree |
I was given a question in Automata that I need to prove or disprove, and I thought about this language:
$$L=\{w \in \{0,1\} ~~ \mathbb{s.t} ~~ |w|=2^i , \forall i=0,...,6 \}$$
Can you please help me to figure out if its minimal DFA contains only 6 states?
How can I get intuition about DFA sizes?
Thanks a lo... |
null |
Jacques Sakarovitch studies the outcome of the various algorithms.
See his paper *The Language, the Expression, and the (Small) Automaton* (CIAA 2005. LNCS 3845), where some results are summarized that are obtained in his book on automata theory. https://doi.org/10.1007/11605157_2
First one should note that the ex... |
You can compute the set of "leaves" in linear-time. I will color the vertices of $G$ as either white or black. Initially all vertices are white. At the end of the algorithm the leaves will be exactly the vertices colored black.
I will additionally associate, to each vertex $v$, a quantity $w(v)$ representing its "whit... |
You can compute the set of "leaves" in linear time. I will color the vertices of $G$ as either white or black. Initially all vertices are white. At the end of the algorithm the leaves will be exactly the vertices colored black.
I will additionally associate, to each vertex $v$, a quantity $w(v)$ representing its "whit... |
You can compute the set of "leaves" in linear time. I will color the vertices of $G$ as either white or black. Initially all vertices are white. At the end of the algorithm the leaves will be exactly the vertices colored black.
I will additionally associate, to each vertex $v$, a quantity $w(v)$ representing its "whit... |
You can compute the set of "leaves" in linear time. I will color the vertices of $G$ as either white or black. Initially all vertices are white. At the end of the algorithm the leaves will be exactly the vertices colored black.
I will additionally associate, to each vertex $v$, a quantity $w(v)$ representing its "whit... |
Consider this problem from [Jeff Erickson's Algorithm book][1],
> Given a tree $T=(V,E)$ in which each node has a reward, and
> $k\in\mathbb{N}$, our goal is to find the maximum number of disjoint paths with length $k$
> (note that a path cannot contains two children of the same node),
> such that sum of rewards ... |
null |
Given a vertex $v$, let $r(v)$ denote $v$'s rewards, let $C_v$ be the set of $v$'s children, and let $T_v$ denote the subtree of $T$ rooted in $v$.
Given a vertex $x$ at depth $d_T(x) \ge k$ in $T$, we denote by $x_i$ the $i$-th ancestor of $x$ in $T$ (in particular $x_0=x$).
Define $C_T(x) =\left( \bigcup_{i=0,\dots... |
Consider this problem from [Jeff Erickson's Algorithm book][1],
> Given a tree $T=(V,E)$ in which each node has a reward, and
> $k\in\mathbb{N}$, our goal is to find a set $S$ of paths, each having length exactly $k$, such that the paths in $S$ are pairwise vertex-disjoint and and the overall reward (defined as the... |
Given a vertex $v$, let $r(v)$ denote $v$'s rewards, let $C_v$ be the set of $v$'s children, and let $T_v$ denote the subtree of $T$ rooted in $v$.
Given a vertex $x$ at depth $d_T(x) \ge k$ in $T$, we denote by $x_i$ the $i$-th ancestor of $x$ in $T$ (in particular $x_0=x$).
Define $C_T(x) =\left( \bigcup_{i=0,\dots... |
Consider exercise 23(c) of chapter "Greedy Algorithms", [*Algorithms*][1] by Jeff Erickson.
> Given a tree $T=(V,E)$ in which each node has a reward, and
> $k\in\mathbb{N}$, our goal is to find a set $S$ of paths, each having length exactly $k$, such that the paths in $S$ are pairwise vertex-disjoint and and the ov... |
|algorithms|dynamic-programming|greedy-algorithms| |
I am studying "Theory of Computation" by Michael Sipser. I am studying the section where he teaches how to convert "RE to FA". He uses empty transitions for union, concat and star, but that is very getting very confusing for me
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/KpIBS.png
... |
Converting Regular Expression to Finite Automata |
|regular-languages|automata|finite-automata|regular-expressions|theory| |
This answer explains an algorithm that finds the minimum number of edges in $O(n\log n)$ time. With more bookkeeping, the path of weight $k$ with that minimum number of edges can also be found in $O(n\log n)$ time.
#### Weight-Length Tree With Offsets
An "OT" will be the shorthand for a "balanced binary search tr... |
The construction that you show from the book of Sipser is known as [Thompson’s construction][1], building a nondeterministic automaton with $\varepsilon$-transitions. Those empty transitions can be removed by a simple algorithm, and then the automaton can be determinized, if needed. (But that can lead to an explosion i... |
I was given a question in Automata that I need to prove or disprove, and I thought about this language:
$$L = \{w\in \{0, 1\}^*\mid 1\le |w| \le 2^6\}$$
Can you please help me to figure out if its minimal DFA contains only 6 states?
How can I get intuition about DFA sizes? |
Suppose the minimal DFA $(Q, \delta, q_0, F)$ contains strictly less than $2^6$ states. Then there exists a state $q$ and two words $u$, $v$ such that $|u| < |v| \leqslant 2^6$ and $\delta(q_0, u) = \delta(q_0, v) = q$.
Now, can you find a contradiction? |
DFA for the language of non-empty words that are no longer than $2^6$ |
I have to write the language of the below $NPDA$(Non-Deterministic Finite Automata).
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/GMNnc.png
I think that from $q_0$ to $q_1$ and then $q_2$, we are actually building the below all the strings of $0$'s and $1$'s of the form $a^nb^n$ wit... |
Determine the language of the NPDA |
|pushdown-automata| |
Consider $L = \{1^n0^n\mid n>0\}$. It seems that the language of your PDA is $L(1L)^*$.
It is not exactly the way you wanted, but I think it is an accurate and short way to write it. |
null |
First of all, the dual of a planar graph is only defined with respect to a planar embedding; for some planar graphs, every embedding gives the same dual graph (as a graph), but this is not always the case.
Given a planar embedding of a planar graph, a *face* is a connected component of the plane with the edges of th... |
I have to write the language of the below $NPDA$(Non-Deterministic Push Down Automata).
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/GMNnc.png
I think that from $q_0$ to $q_1$ and then $q_2$, we are actually building the below all the strings of $0$'s and $1$'s of the form $a^nb^n$ ... |
null |
I have read that when programming it is good to identify relations -- invariants -- that should hold true throughout the program, and it is good to insert assertions throughout the code to check that the invariants are maintained.
I can see how programs that involve mathematics can have invariants, i.e., some mathem... |
Are there invariants in text processing problems? |
|algorithms|formal-methods|software-verification|loop-invariants|software-testing| |
Consider $L = \{1^n0^n\mid n>0\}$. It seems that the language of your PDA is $L(1L)^*$.
It is not exactly the way you wanted, but I think it is an accurate and short way to write it.
You could be a bit more verbose and write it as:
$$\{1^{n_1}0^{n_1}11^{n_2}0^{n_2}1…11^{n_k}0^{n_k}\mid k \geqslant 1 \wedge \fo... |
Yes. One can find invariants in any program. The notion is well-defined and meaningful in any program (whether it is useful in practice is a different question).
Normally identifying invariants is most useful whenever there are loops (or recursion). Straight-line code is usually easy to reason about, so there is ... |
What kind of problems in the world can be classified into PSPACE categories? |
null |
If “the only thing a computer can do is adding”, then a computer can do everything it does just by adding.
But by adding you can’t change a 1 to a 0. There are many things you can’t do just by adding.
What you do need to do anything a computer can do: Perform a NAND operation. Select memory. Produce electrical ... |
I’m looking for a distribution that is non negative , or has good tail bounds (so non negative with high probability) and maximizes the following property:
$X_1, X_2, …, X_n$ are n IID samples of the distribution \
$Y = max(X_1, X_2, …, X_n) $\
X = a sample from the distribution
Maximizes $$\frac{E[Y]}{ E[X]}... |
A (WHP) non-negative distribution that maximizes the ratio of expected maximum of n independent samples over the mean of the distribution |
|probability-theory|statistics|balls-and-bins| |
null |
Computers can perform any algorithm using only addition (or even using only the [x86 MOV instruction][1]).
But what they have is a set of instructions aiming to maximize performance.
A computer that only use the add operator will be slow in doing multiplication. To get around this, computers have hardware-impleme... |
null |
I’m looking for a distribution that is non-negative, or has good tail bounds (so non-negative with high probability) and maximizes the ratio between the expected maximum of $n$ iid samples and the mean.
That is, if $X_1,\ldots,X_n$ are iid samples from the distribution, $Y = \max(X_1,\ldots,X_n)$, and $X$ is anothe... |
Distribution maximizing ratio of expected maximum over the mean |
I have to design an NPDA(Non-Deterministic Finite Automata) for all the strings over
$\{a, b \}^*$, which have equal numbers of $a$'s and $b$'s but do not end up with an $a$.
I know how should we create an NPDA for the strings with an equal number of $a$'s and $b$'s.
But I don't know how to add this condition to it... |
NPDA which accepts all the strings of a's and b's that have equal number of a's and b's, but does not end up with an a |
|pushdown-automata| |
For non-negative random variables, the answer is $\Theta(n)$.
Notice that $Y \leq X_1 + \cdots + X_n$, and so $E[Y] \leq n E[X]$.
In the other direction, consider the following random variable: $X = 1$ w.p. $1 - 1/n$, and $X = n$ otherwise. On the one hand, $E[X] = 1 - 1/n + n/n \approx 2$. On the other hand, $\P... |
I have to design an NPDA(Non-Deterministic Push Down Automata) for all the strings over
$\{a, b \}^*$, which have equal numbers of $a$'s and $b$'s but do not end up with an $a$.
I know how should we create an NPDA for the strings with an equal number of $a$'s and $b$'s.
But I don't know how to add this condition t... |
null |
In linux, when I access /proc for a particular program it shows memory mapping for the program in maps file.
Something like this:
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/UdKSi.png
I wanted to know what is this [stack] memory mapped to i.e the kernel stack or the user stack a... |
Understanding maps file in /proc directory for a process |
|memory-management| |
null |
Given the problem of having a **sorted array** $A$, an element $x$ to be searched for in the array $ A $, what is a lower-bound on the process of finding $x$ in $A$?
The answer is $ \Omega(log n) $ because I was told that $ n $ is the number of leaves in the decision tree and so $ log n $ will be the height of the t... |
Decision tree for searching element in sorted-array |
|algorithms|trees|search-algorithms|decision-tree| |
That's a question from a home assignment by T. Zur
> Say that a Turing machine $M$ is monotone if it halts on every input,
> and if the length of $w$ is greater than the length of $w`$ then $M$
> performs more steps on $w$ than on $w`$.
>
> Prove that $MON$ is undecidable.
My idea is to define a reduction fr... |
Prove that $MON = {<M> : M is monotone}$ is undecidable |
|reductions|halting-problem| |
That's a question from a home assignment by T. Zur:
> Say that a Turing machine $M$ is *monotone* if it halts on every input,
> and if the length of $w$ is greater than the length of $w'$ then $M$
> performs more steps on $w$ than on $w'$.
>
> Prove that MON is undecidable.
My idea is to define a reduction f... |
$\mathrm{MON} = \{\langle M\rangle : \text{$M$ is monotone}\}$ is undecidable |
Your answer is correct
What might seem missing is that $M'$ erases any input, writes $w$ and simulates $M$ on $w$, so it might seem that for any input (say $x$ which we erase), $M'$ takes the same number of steps (simulating $w$), but $M'$ needs to take more steps on larger inputs!
The thing is when you erase the... |
Given the problem of having a **sorted array** $A$, an element $x$ to be searched for in the array $ A $, what is a lower-bound on the process of finding $x$ in $A$?
The answer is $ \Omega(\log n) $ because I was told that $ n $ is the number of leaves in the decision tree and so $ \log n $ will be the height of the... |
{"Voters":[{"Id":125500,"DisplayName":"Moslem"}]} |
Can anyone please help me with a better solution than O(n^3) for this problem?
So the problem is given a string, we want to output the substring's length where freqency[c1] - frequency[c2] is MAX.
c1 = Most frequent character
c2 = Least frequent character
e.g
'aaabbbbbabcbbbaaaa' => 8 ( corresponding to th... |
Maximum difference between maximum and minimum frequency of characters in a subarray of a given array of characters. ( Characters are ['a'-'z'] ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.