instruction stringlengths 0 29.8k ⌀ |
|---|
It can be seen as parallel computation wherein multiple processes can be running concurrently. An NFA splits into these different paths non-deterministically and will accept a word if at least one of these paths accept |
How would you modify the Product Construction for DFAs to find a DFA that recognises the union of two regular languages with different alphabets. I am not looking for a way of finding an NFA then converting that to an equivalent DFA but explicitly modifying the Product Construction Theorem.
|
Product Construction for DFAs with different alphabets |
|automata|finite-automata|computation-models| |
To understand the Pumping Lemma, I'm going to prove that the language $L = \{0^n1^m0^n | n,m \geq0\}$ is not regular. I choose string $w = 0^{p/2}1^{p/2}0^{p/2}$, for any even number $p$. Clearly $|w| > p$. I use the following decomposition
- $x = 0^{p/2}$
- $y = 1^{p/2}$
- $z = 0^{p/2}$
Clearly for any $i$,... |
Pumpiing Lemma for $0^n1^m0^n$ |
|regular-languages|pumping-lemma| |
null |
To understand the Pumping Lemma, I'm going to prove that the language $L = \{0^n1^m0^n | n,m \geq0\}$ is not regular. I choose string $w = 0^{p/2}1^{p/2}0^{p/2}$, for any even number $p$. Clearly $|w| > p$. I use the following decomposition
- $x = 0^{p/2}$
- $y = 1^{p/2}$
- $z = 0^{p/2}$
Clearly for any $i$,... |
Pumpiing Lemma for $0^n1^m0^n$ and $0^{3n}$ |
null |
We can adapt the product construction, but we can also change the original DFA $A_1$ over alphabet $\Sigma_1$ into a new DFA $A$ accepting the same language, but over a larger alphabet $\Sigma\supseteq \Sigma_1$.
Just add a new dummy state $d$ and add transitions to $d$ from every state, for every extra letter $\sig... |
Consider the following code and equivalently transformed versions:
count= 0;
for(int i = 1; i<=n; i++) {
for(int j = i+1; j<=n-i; j++) {
count++;
}
}
----------
count= 0;
for(int i = 1; i<=n; i++) {
count+= max(0, n - 2*i);
}
--... |
Consider the following code and equivalently transformed versions:
count= 0;
for(int i = 1; i<=n; i++) {
for(int j = i+1; j<=n-i; j++) {
count++;
}
}
----------
count= 0;
for(int i = 1; i<=n; i++) {
count+= max(0, n - 2*i);
}
--... |
To show that a language is not regular using the pumping lemma you want to show that **for every** $p$, there **exists** some word $w$ such that, **for every* decomposition of $w$ as $xyz$ with $|xy| \le p$ and $|y| \ge i$, **there exists** some $i \ge 0$ such that $xy^i z \not\in L$.
The quantifiers and their order... |
To show that a language $L$ is not regular you need to argue that the pumping lemma does not hold. That is, you want to show that **for every** $p$, there **exists** some word $w$ such that, **for every** decomposition of $w$ as $xyz$ with $|xy| \le p$ and $|y| \ge i$, **there exists** some $i \ge 0$ such that $xy^i z ... |
In the first for loop
```
for(int i = 1;i<=n;i++)
```
the number of iterations increases linearly with the size of the input ($n$).
The second,
```
for(int j = i+1; j<=n-i; j++)
```
the number of iterations is also linear for$n$. In this case the iterations are not exactly $n$ (in fact they are $(n-i)-(i+1... |
If you want to calculate time complexity using asymptotic notation, it's even easier (that's why it's so useful!).
In the first for loop
```
for(int i = 1;i<=n;i++)
```
the number of iterations increases linearly with the size of the input ($n$).
The second,
```
for(int j = i+1; j<=n-i; j++)
```
the num... |
In an undirected graph it takes $O(|E|)$ time to visit all nodes in a simple graph using BFS according to our lecture notes. But why can't you visit them all in $(|V|)$ time instead? |
Does it require O(|E|) time to visit all nodes? |
|graph-traversal| |
Virtual addresses can correspond to data in RAM or on disk and the system keeps address translation tables saying for instance:
- address 37 is mapped to RAM page 7000, at offset 37 (hence address 7037)
- address 37 is mapped to disk, track 345, sector 25, at offset 37.
When the CPU wants to access that virtua... |
Virtual addresses can correspond to data in RAM or on disk and the system keeps address translation tables saying for instance:
- address 15037 is mapped to RAM page 7000, at offset 37 (hence address 7037)
- address 15037 is mapped to disk, track 345, sector 25, at offset 37.
(Addresses are mapped by whole pag... |
For every $i$ we define $\Sigma_i=${$1, 2, ..., i$} and a language over said $\Sigma_i$:
$L_i=${$w\in \Sigma_i^*| \exists \sigma \in \Sigma_i :\sigma$ does not appear in $w$}
And I'm asked to prove that for all $i>2$, $L_i$ has an NDA with $i+1$ vertices.
I've had the idea of implementing it as a chain of ve... |
Proving existence of NDA with specific amount of vertices |
|computation-models|nondeterminism| |
null |
In an undirected graph it takes $O(|V| + |E|)$ time to visit all nodes in a simple graph using BFS according to our lecture notes. But why can't you visit them all in $(|V|)$ time instead? |
I have a list with strings like below.
abc.* abc.def.* abc.xyz.*
Since abc.def.* is an extension of abc.* my method should detect such strings.
How can I achieve this efficiently in Java ? I know I can do it with two loops. Trying to reduce the time complexity. Any thoughts ?
Thanks.
Tried o(n^2) solut... |
**Problem:** Given a list of wild card strings(wild card is a * which is always at the end of a string), determine if the list has strings that are extension of another wild card string in the list.
Examples:
1. [abc.*, abc.def.* ]
- the list has field abc.def.* which is an extension of abc.*
2. [abc.xyz.*, def.*... |
Particularly for BFS you need to pass over all edges. However, it is a lower bound for any algorithm for that — let's look at the simplified problem of testing whether the graph is connected. Let's look at the following two cases:
1. The graph is made of two random connected graphs.
2. The graph is made of two ra... |
For every $i$ we define $\Sigma_i=${$1, 2, ..., i$} and a language over said $\Sigma_i$:
$L_i=${$w\in \Sigma_i^*| \exists \sigma \in \Sigma_i :\sigma$ does not appear in $w$}
And I'm asked to prove that for all $i>2$, $L_i$ has an NFA with $i+1$ vertices.
I've had the idea of implementing it as a chain of ve... |
Proving existence of NFA with specific amount of vertices |
null |
null |
Looking at [your code][1], I think you may be looking for [model-based testing][2].
In model-based testing, you create a model: an explicit declarative specification of the behavior expected from your system. This is what your line
StateMachine<Human> fsm = StateMachineBuilder.create(Human.class)
... |
Use a [trie](https://en.wikipedia.org/wiki/Trie), also known as a prefix tree. The running time will be (approximately) linear in the size of the input. |
If I understand correctly, you are dealing with a machine with states, and deterministic transitions to other states caused by events. This is an FSM.
Such an automaton is described by a state/event matrix, whatever the way transition data is supplied. |
## Background
Let $n, m \in \mathbb{N}$ with $n < m$. We call $C : \{0, 1\}^n \rightarrow \{0, 1\}^m$ an error correcting code of distance $\delta \in [0,1]$ if for any distinct $x^1, x^2 \in \{0,1\}^n$, it is the case that
$$\Delta_C(x_1, x_2) := \frac{|\{i \in [m] : C(x^1)_i \neq C(x^2)_i\}|}{m} \geq \delta$$
... |
How is this code derived from the concatenated Walsh-Hadamard Reed-Solomon code? |
|error-correcting-codes| |
I was working on a problem for some time now, and I made a data structure to solve it. To my surprise, I could not find any instance of this data structure on the internet (though I am certain someone has thought of this).
Put simply, it is a sorted linked list and a sorted array, with the array pointing to spots a ... |
I am going through notes on Computability theory and Galosis Theory by Russel Miller. In it, many times the phrase "set of all programs" is used. Could someone give a formal definition of what the set of all programs are? |
What do people mean they say "set of all programs" in computability theory? |
|turing-machines|computability| |
I have a matrix (input):
| -- | c1 | c2 | c3 |
|:--:|:--:|:--:|:--:|
| r1 | AA | BB | CC |
| r2 | CC | RR | BB |
| r3 | EE | DD | FF |
| r4 | KK | DD | EE |
| r5 | DD | GG | KK |
| r6 | PP | QQ | KK |
1. Let's call each matrix cell a `namespace`. If two rows begin from the same namespace, then such a names... |
Assuming [these][1] are the notes you are talking about, the author informally described a Turing machine with the following excerpt
> For our purposes, a Turing machine is an ordinary computer, operating
according to a finite program, which accepts a natural number as input and
runs its program in discrete steps ... |
null |
The term "heap" has majorly two meanings in computer science -
1. The "heap" memory in the context of memory.
2. The "heap" data structure as the representation of a priority tree as an array.
I can understand the use of the word "heap" in the context of memory as it correlates to the literal meaning of the wor... |
Why are heaps called heaps in graph theory? |
|graphs|terminology|heaps| |
The term "heap" has majorly two meanings in computer science -
1. The "heap" memory in the context of memory management.
2. The "heap" data structure as the representation of a priority tree as an array.
I can understand the use of the word "heap" in the context of memory as it correlates to the literal meaning... |
I have a weakly-connected weighted digraph $G$, and I'd like to divide it into $k$ weakly connected subgraphs $G_k$ each with approximate equal total weight $w_{T_k}$ ($w_{T_k}$ = sum of weights of all edges in $G_k$).
I'm not able to find exactly what I'm looking for using `networkx`, so I'm wondering if there's ... |
Having this, if I pass an empty input to the machine it is supposed to be accepted, isn't it? It doesn't say 'exactly'. |
Turing machine: w contains twice as many 0s as 1s |
|turing-machines| |
If m = Ram quantity in GB, b = bus width in bits, and n = a nonnegative integer, it appears that b = m•2^n and or m = w/2^n, what do the variables represent physically? I.e., what physically changes to, say, a GPU design if you change b, m, or n? E.g., how is the design different for m₁ = 5 and n₁=7 instead of m₂=10 ... |
How are memory busses and capacity determined? |
|memory-hardware| |
There's nothing to explain. It's just a name. Instead of "heap", the name could have been "giraffe" or "hxfq" or anything else. A rose by any other name is still a rose.
The definition of a heap data structure is found in standard references, e.g., https://en.wikipedia.org/wiki/Heap_(data_structure). |
It seems that the use of *heap* to denote a priority queue implemented as an implicit binary tree was introduced in the original Heapsort article: Williams, J. W. J. (1964), "Algorithm 232 - Heapsort", Communications of the ACM, 7 (6): 347–348.
A well-known chatbot gives the following explanation: "Williams chose to... |
It seems that the use of *heap* to denote a priority queue implemented as an implicit binary tree was first introduced in the original Heapsort article: Williams, J. W. J. (1964), "Algorithm 232 - Heapsort", Communications of the ACM, 7 (6): 347–348.
A well-known chatbot gives the following explanation: "Williams ch... |
You are correct in that for many representations of graphs, you could iterate through all the nodes in $O(|V|)$ time. But if someone wants to visit all the nodes according to a BFS order (for instance, producing the BFS tree on |V| nodes) it will require $O(|V|+|E|)$ time. That is, if one wants to process the nodes in ... |
I am looking at the problem of finding the quadrilateral of minimum area that encloses a convex polygon.
I found the following articles:
1. An Optimal Algorithm for Finding Minimal Enclosing Triangles by Joseph O'Rourke, Alok Aggarwal, Sanjeev Maddila, and Michael Baldwin, in time $O(n)$, for triangles;
2. Imp... |
Minimal bounding quadrilateral of a convex polygon |
|computational-geometry|polygons| |
I have the main idea, yet I'm uncertain on how to construct this PDA (in terms of states, transitions)
I want to use the fact that the language $L=${$w\in\Sigma^* : w=u_1\circ u_2 , |u_1|=|u_2| , u_1\neq u_2$} can be constructed using a PDA, and that since $u_1\neq u_2$ there must be atleast one character which is i... |
Constructing a PDA for $L=${$\exists i,k\in \mathbb{N} : |w|=2k, w_i \neq w_{k+i}$} |
|pushdown-automata|nondeterminism| |
null |
To show that a language $L$ is not regular you need to argue that the pumping lemma does not hold. That is, you want to show that **for every** $p$, there **exists** some word $w$ such that, **for every** decomposition of $w$ as $xyz$ with $|xy| \le p$ and $|y| \ge i$, **there exists** some $i \ge 0$ such that $xy^i z ... |
I am studying an optimization problem which can be recast as an LP I have described below. I wish to understand the structure of optimizers of the original problem by studying the optimizers of the LP. There are several versions of assignment problems that are comparable to our LP, such as the many-to-many and many-to-... |
Preference based assignment problem to maximize utility without the constraint that every item/person receives assignment(some portion of goods) |
|optimization|linear-programming|matching|assignment-problem| |
To resolve $$T(n)=T(\tilde{a}n)+n$$
you can apply the Master
Theorem(https://en.wikipedia.org/wiki/Master_theorem_(analysis_of_algorithms)):
the recurrence:
\begin{equation}
T(n)
= \begin{cases}
a T(n / b) + f(n) & n > 1 \\
T_1 & n = 1
... |
I have the main idea, yet I'm uncertain on how to construct this PDA (in terms of states, transitions)
We can assume the alphabet $\Sigma$ is {$0,1$}, proving for $\Sigma=${$0,1$} is a sufficient proof that 'covers' all $\Sigma$'s such that $|\Sigma|\geq 2$.
I want to use the fact that the language $L=${$w\in\... |
I have the main idea, yet I'm uncertain on how to construct this PDA (in terms of states, transitions)
We can assume the alphabet $\Sigma$ is {$0,1$}, proving for $\Sigma=${$0,1$} is a sufficient proof that 'covers' all $\Sigma$'s such that $|\Sigma|\geq 2$.
I want to use the fact that the language $L=${$w\in\... |
I think, as it says [Shar](https://cs.stackexchange.com/users/119516/shar) you have a mistake, given that:
\begin{aligned}
T(n)&=5T(\frac{n}{3})+2n\\
&=5\big (
5T(\frac{\frac{n}{3}}{3})+2\frac{n}{3}
\big )+2n\\
&\neq 5\left[5T(\frac{n-1}{3^2}) + 2(n-1)\right] + 2n \\
\end{aligned}
let's call $a=\frac{1}{... |
I am looking for a O(1) solution for *finding the number of substrings a character is part of.*
For instance, let `s = "abcde"` and all substrings of s are
`a, b, c, d, e, ab, bc, cd, de, abc, bcd, cde, abcd, bcde, abcde`
Now 'a' is part of `a, ab, abc, abcd, abcde`
So I guess The first (and the last char... |
Find the no of substrings a character is part of |
|algorithms|strings|substrings| |
Preference based assignment problem to maximize utility |
|graphs|optimization|linear-programming|matching|assignment-problem| |
I am wondering about a way to CNF encode an EqualsK constraint with two possible values. In other words, I want to solve for the equation:
$$
(\sum_{i=1}^n x_i = A) \lor (\sum_{i=1}^n x_i = B)
$$
There are CNF encodings already discussed for encoding EqualsK constraints with one value K, like [here](https://www... |
Encoding SAT EqualsK Constraint with Two Possible Values |
|satisfiability|constraint-satisfaction| |
null |
One option is to use a normal EqualsK, as
$$(t \lor \text{Equals}(A,x_1 \cdots x_n)) \land (\neg t \lor \text{Equals}(B,x_1 \cdots x_n))$$
where $t$ is a fresh variable. It is easy to convert this to CNF by distributing the $t \lor \cdots$ into the clauses of the EqualsK constraints.
Another option is to coun... |
If you want to calculate time complexity using asymptotic notation, it's even easier (that's why it's so useful!).
In the first for loop
```
for(int i = 1;i<=n;i++)
```
the number of iterations increases linearly with the size of the input ($n$).
The second,
```
for(int j = i + 1; j <= n - i; j++)
```
t... |
I am looking for a O(1) solution for *finding the number of substrings a character is part of.*
For instance, let `s = "abcde"` and all substrings of s are
`a, b, c, d, e, ab, bc, cd, de, abc, bcd, cde, abcd, bcde, abcde`
Now 'a' is part of `a, ab, abc, abcd, abcde`
So I guess The first (and the last char... |
In your length-5 string, your indices are $0,1,2,3,4$.
Take a character like $b$ of index 1. It will be in every substring defined by $(i,j)$ where $i$ can be $0,1$ and $j$ can be any of $1,2,3,4$. Can you see why the answer for $b$ is 8 without having the write them all out?
Take character $c$ at position index ... |
I am looking for a O(1) solution for *finding the number of substrings a character is part of.*
For instance, let `s = "abcde"` and all substrings of s are
`a, b, c, d, e, ab, bc, cd, de, abc, bcd, cde, abcd, bcde, abcde`
Now 'a' is part of `a, ab, abc, abcd, abcde`
So I guess The first (and the last char... |
Given 2 arrays $A, B$ each of size $n$. If we want to find if the two arrays satisfy the conidiont that $A[i] + B[i] \gt=k$, it's sufficient to fulfill 3 conditions below, where $A.size()$ is the number of elements of $A$, which should equal $B$:
1. sum of all elements of $A$ and $B$ is $\ge=\frac{A.size()}{k}$
2... |
Check if Two Arrays Sorted in Decreasing and Increasing Order Satisfy a Condition |
|arrays|permutations| |
Given 2 arrays $A, B$ each of size $n$. If we want to find if the two arrays satisfy the condition that $A[i] + B[i] \ge k$ for all indices $i$, it's sufficient to fulfill 3 conditions below:
1. sum of all elements of $A$ and $B$ is $\ge nk$
2. Max element of $A$ and min element of $B$ is $\ge k$ (edge case)
3.... |
Given 2 arrays $A, B$ each of size $n$. If we want to find if the two arrays satisfy the condition that $A[i] + B[i] \ge k$ for all indices $i$, it's sufficient to fulfill 3 conditions below:
1. Sum of all elements of $A$ and $B$ is $\ge nk$
2. Sum of max element of $A$ and min element of $B$ is $\ge k$ (edge cas... |
**Preliminaries**. Let $n,m \in \mathbb{N}$. Let our alphabet be $\Sigma = \{0,1\}$, with languages $ L \subseteq \Sigma^n$ and $ L' \subseteq \Sigma^m$. We follow the [standard definition](https://en.wikipedia.org/wiki/Finite-state_machine#Mathematical_model) for finite-state automata, in particular, an FSM has a fini... |
Counting States in a Restricted Automaton |
|regular-languages|finite-automata| |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.