instruction stringlengths 0 29.8k ⌀ |
|---|
|arrays|substrings| |
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... |
{"Voters":[{"Id":125500,"DisplayName":"Moslem"}]} |
Your problem can be solved in linear time in the length of the input string.
Let $s=s_1s_2s_3\ldots$ be your input string. For $0<i\le j \le |s|$, let $n(i,j,c)$ be the number of occurrences of $c$ in $s_i s_{i+1} \dots s_j$.
Let $m^*$ be the measure of an optimal solution. Now guess the values of $c_1$ and $c_2$... |
We can provide an $O(n)$ algorithm for such a problem
For every pair of characters $(c_1,c_2)$, we take the input string, ignore all other characters, replace $c_1$ by $1$, replace $c_2$ by $-1$ and then compute the largest sum of a contiguous subarray, which will be the deviation ($f_{max} - f{min}$) for this pair
... |
I was trying to find out how to find whether $N$ is a perfect power or not for some $a$ and $b$ (so the algorithm should discover that it is not a perfect power if it is not expressible in the form $a^b$).
My intuition tells me that for every value of the exponent $b$ we can binary search $a$ in the set $\{ 1,...,N-... |
How does one find out whether $N = a^b$ for some integer $a$ and $b$? |
|algorithms|decision-problem|diophantine-equation| |
Let's say that we want to convert the regular expression: (ab + a)* to Finite Automata, where '+' is union and '*' is kleene star. Using the Thompson method, [Thompson Method][1]
I end up with this:[![enter image description here][2]][2]
[1]: https://en.wikipedia.org/wiki/Thompson%27s_construction#Rules
... |
How to cross verify the resultant E-NFA in "Regular Expression to E-NFA" is correct? |
|regular-languages|finite-automata|regular-expressions|nondeterminism|theory| |
Let's say that we want to convert the regular expression: (ab + a)* to Finite Automata, where '+' is union and '*' is kleene star. Using the Thompson method, [Thompson Method][1]
I end up with this:[![enter image description here][2]][2]
[1]: https://en.wikipedia.org/wiki/Thompson%27s_construction#Rules
... |
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... |
You should try the substitutions in order so that you don't get a loop, here is the solution
$q1 = \varepsilon$
$q_2 = q_1 \varepsilon + q_8 \varepsilon$
$q_3 = q_2 \varepsilon$
$q_4 = q_3a$
$q_5 = q_4b$
$q_6 = q_2 \varepsilon$
$q_7 = q_6a$
$q_8 = q5 \varepsilon + q_6 \varepsilon$
$q_9 = q_8... |
I was wondering if someone could help resolve some issues I have understanding the proof given for the Cook-Levin theorem provided in the Sipser text (3rd edition) – as this proof has truly stumped me.
Having read through this proof numerous times, the only issue I have is that I simply do not understand how it actu... |
How does the 'proof' of the Cook-Levin theorem, actually prove the Cook-Levin theorem? |
|complexity-theory| |
How do I being to show that if $L_{1}$ is Turing-recognizable language over $\Sigma=\{0,1\}$, then $L_{2} = \{ww^R | w ∈ L_{1} \}$ is a Turing recognizable language too.
There is another similar problem, but instead of the language being recognizable, it's decidable. If anyone has any ideas on how to approach both o... |
How to show that language is Turing-recognizable and Turing-decidable? |
|turing-machines|turing-recognizable| |
The following is a description of an acceptor/decider for $L_2$. If the length $|x|$ of the input $x$ is odd, then reject. Otherwise consider the subword $x_1$ (resp $x_2$) consisting of the first (resp. last) $|x|/2$ symbols of $x$. Check whether $x_1 = x_2^R$. If that is not the case, then reject. Otherwise, simulate... |
With careful analysis we can ascertain that this reduction works, meaning that the $NM$ accepts $w$ if and only if $\phi$ is satisfiable (falsifying your claim that $\phi$ is satisfiable anyways)
Lets first have a high level overview of the reduction, $NM$ runs in $O(n^k)$ on input $w$, where $\vert w \vert = n$
... |
With careful analysis we can ascertain that this reduction works, meaning that the $NM$ accepts $w$ if and only if $\phi$ is satisfiable (falsifying your claim that $\phi$ is satisfiable anyways)
Lets first have a high level overview of the reduction, $NM$ runs in $O(n^k)$ on input $w$, where $\vert w \vert = n$
... |
Here is what a $TM$ for $L_2$ would do
We first check that input $x$ is not of odd length, if so we reject
Next we cut $x$ into two halves and check that the second half is the reversal of the first, hence the string is of the form $ww^R$
Next, we run the recogniser/decider of $L_1$ on $w$ (the first half of... |
Can anyone please help me solve this better than O(|a-b|*n)?
Given an array of both -ve and +ve numbers, we want to find the maximum sum between length a & b.
Example
Input:
8 1 2
-1 13 -2 5 13 -5 2 2
Output:
18
Here a = 1 , b = 2
Although Maximum sum is 29, Max sum of length between [1-2] is ... |
Maximum subarray sum of given length range |
|arrays|greedy-algorithms|maximum-subarray| |
Can anyone please help me solve this better than O(|a-b|*n)?
Given an array of both -ve and +ve numbers, we want to find the maximum contiguous subarray sum **between** length a & b.
Example
Input:
8 1 2
-1 13 -2 5 13 -5 2 2
Output:
18
Here a = 1 , b = 2
Although Maximum sum is 29, Max sum of ... |
null |
null |
I know that searching a collection can be done in $O(1)$(on average) using hash tables. I would like to know if there is an algorithm that could be as performance without using arrays.
My main motivation for this question is to know if it is possible to build a search collection algorithm in $O(1)$ using just functi... |
What is the lower bound on searching a collection if no arrays(Random access memory) are allowed? |
|time-complexity|data-structures|lambda-calculus|functional-programming|lower-bounds| |
null |
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 = ... |
I have a large system of $3$-$XORSAT$ constraints (i.e. up to $3$ variables per constraint) and this can be represented in matrix form as a linear algebra problem $Ax=b$ $mod$ $2$. Solvability (i.e. the satisfiability of the $3$-$XORSAT$ system) can be tested by using Gaussian elimination which involves multiple rounds... |
Is there an alternative method to using Gaussian elimination in order to solve 3-XORSAT |
|algorithms|satisfiability|linear-algebra|sparse-matrices| |
By augmenting an AVL tree you can implement a data structure that maintains a multi-set $S$ under the following $O(\log |S|)$-time operations:
- Add($S, x$) Add a given integer $x$ to $S$.
- Offset($S, x$): Increase the value of all element in $S$ by a given integral offset $x$.
- Delete($S,x$) Delete (one copy of)... |
By augmenting an AVL tree you can implement a data structure that maintains a multi-set $S$ under the following $O(\log |S|)$-time operations:
- Add($S, x$) Add a given integer $x$ to $S$.
- Offset($S, x$): Increase the value of all element in $S$ by a given integral offset $x$.
- Delete($S,x$) Delete (one copy of)... |
I would say, it depends.
Overall there are several strategies how a cache could be incorporated into a process. Few of these options are:
- read through: a client reads from cache, and if the cache does not have a value, then the cache itself reads the data from the store. And the cache saves the value before being... |
null |
Need to show a reduction of max flow to min cost (not min cost max flow!!) |
How to show that the max flow problem can be formulated as a min-cost flow problem? |
|network-flow| |
I am studying the Master Theorem, but there is a case in which I have no knowledge on how one should proceed. If it's given:
$T_1(n)= 1$ if n=1
$T_1(n)= 4T_1(\frac n2) + \sqrt{3n}+1$ otherwise.
For this case $T_1(n) \in \Theta(n^2)$
We then have:
$T_2(n)= 1$ if n=1
$T_2(n)= 14T_2(\frac n4)+ T_1(n)=14T... |
Master Theorem but with 2 different T's from two different recurrent trees |
|algorithms| |
null |
null |
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... |
By augmenting an AVL tree you can implement a data structure that maintains a multi-set $S$ under the following $O(\log |S|)$-time operations:
- Add($S, x$): Add number $x$ to $S$.
- Offset($S, x$): Increase the value of all element in $S$ by number $x$.
- Delete($S,x$): Delete (one copy of) number $x$ from $S$
- ... |
null |
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, which its machine would be like this:
[![e... |
null |
[Orthogonal arrays][1] often appear in probabilistic algorithms. They can be efficiently constructed from, e.g., [BCH codes][2].
But is there an efficient algorithm that can verify if an array is orthogonal? I would be particularly curious about the strength-4 arrays.
[1]: https://en.wikipedia.org/wiki/Orthogo... |
Verify if array is w-orthogonal |
|probabilistic-algorithms|error-correcting-codes| |
I am trying to understand how the input size, problem size and the asymptotic behavior of an arbitrary algorithm given in pseudo code format differ from each other. While I fully understand the input and the asymptotic behavior, I have problems understanding the problem size. To me it looks as if problem size= space co... |
Problem size and how it's different then the input for an algorithm |
|algorithms| |
I'm not sure what you mean by *problem size*, so let me give a few examples:
- We often analyze graph algorithms in terms of $|V|$ and $|E|$.
- We often analyze algorithms on arrays (sorting, binary search) in terms of $n$, the size of the array.
- We often analyze algorithms on square matrices in terms of $n$, th... |
I am trying to understand how the input size, problem size and the asymptotic behavior of an arbitrary algorithm given in pseudo code format differ from each other. While I fully understand the input and the asymptotic behavior, I have problems understanding the problem size. To me it looks as if problem size = space c... |
Problem size and how it's different than the input for an algorithm |
The asymptotic behavior can refer to any "measurand", such as the processor time taken, but also the space consumption, the number of comparisons, the number of SQL queries of whatever you want.
The input size indeed denotes the space taken by the input data (quite often written $n$, which can be itself an asymptoti... |
Consider a logical address space of 4096, page size = 1024
physical memory = 8192
Page No Frame No
0 7
1 4
2 2
3 3
What is the physical address corresponding to logical address 500, 1000, 2000, 3000, and 4000?
Can I know how to solve this step by step?
O... |
Calculate Physical Address Corresponding to Logical Addresses |
|paging| |
Consider a graph $G$ and let $s$ (resp. $t$) be the source (resp. target) vertex for your max-flow problem. Let $U$ be an upper bound to the max flow (for example the sum of the capacities of the edges leaving $s$, or the sum of the capacities of the edges entering $t$).
Construct an instance of min-cost flow where... |
Consider a logical address space of 4096, page size = 1024
physical memory = 8192
[![enter image description here][1]][1]
What is the physical address corresponding to logical address 500, 1000, 2000, 3000, and 4000?
Can I know how to solve this step by step?
Only one example would be enough.
[1]: htt... |
Since you have not mentioned word size, I am going to assume they are same across all three terms. Your problem boils down to calculating which page number(address range) the logical address lies in, finding offset of that address within the page and adding the offset to the physical address where that page is mapped.
... |
The below is with 0-based indexing for the buckets.
* We assume we have some hash function $h(k) \rightarrow [0,1)$.
* When looking up $k$ check the last node (index $N-1$) and the node $\lfloor Nh(k) \rfloor$.
* When inserting $k$ we always insert in the last node (index $N-1$).
* When $N$ changes to $N'$ (which... |
I know that searching a collection can be done in $O(1)$ time(on average) using hash tables. I would like to know if there is an algorithm that could be as performance without using arrays.
My main motivation for this question is to know if it is possible to build a search collection algorithm in $O(1)$ time using j... |
null |
I know that retrieving an item in a collection can be done in $O(1)$ time(on average) using hash tables. I would like to know if there is an algorithm that could be as performance without using arrays.
My main motivation for this question is to know if it is possible to build a retrieve element algorithm in $O(1)$ t... |
What is the lower bound on retrieving an item in a collection if no arrays(Random access memory) are allowed? |
There are people and the food they prefer:
John -20> Apple
John -10> Pear
Ethan -20> Apple
Ethan -5> Orange
Michael -10> Pear
Michael -10> Limon
The numbers indicate how strongly they prefer the respective food.
i.e. *John likes Apple more than Pear* (20 > 10). And so for everyone.
The task... |
What is this task type? |
|algorithms|optimization| |
Use this correspondence table:
Logical addresses / Physical addresses
0-1023 7168-8191
1024-2047 4096-5119
2048-3071 2048-3071
3072-4095 3072-4095 |
let G be the grammar bellow
$$ G=( {A,S}, {a,b}, S, P) $$ and the grammaer rule's are
$$ S\rightarrow aAb|Sb $$
$$ A\rightarrow aAb|ab $$
1. what is the language of the grammar L(G)?
2. prove in induction that L(G) is the grammar language.
my attempt
I think the language is
$$L= \ \{a^nb^{n+k}|n\geq2,k... |
let G be the grammar bellow ($ S\rightarrow aAb|Sb $) ($ A\rightarrow aAb|ab $) prove in induction that L(G) is the grammar language |
|automata|formal-grammars|induction| |
I was wondering whether someone could help me resolve an issue I have understanding the proof given for Savitch’s theorem in the Sipser text (3rd edition). The question I have is more or less identical to the first question given in a previous post (https://cs.stackexchange.com/questions/22745/the-crux-of-savitchs-theo... |
Difficulty understanding the CANYIELD function in the Sipser text's proof of Savitch’s theorem |
|space-complexity| |
null |
> Let $G = (\{A,S\}, \{a,b\}, S, P\}$ be the grammar with the following productions:
> \begin{align}
& S \to aAb | Sb \\
& A \to aAb | ab
\end{align}
>
> 1. What is the language $L(G)$ generated by the grammar?
> 2. Prove your answer to 1. by induction.
Here is my attempt.
I think that the language generated... |
Language generated by $S \to aAb|Sb$, $A \to aAb|ab$ |
Let $$ L=\{ a^c|c\ is\ composite \} $$
Dirichlet theorem:
if (a,b) = 1 then exists infinity amount of prime numbers from the form
$$ an+b $$.
prove that L is not regular with pumping Lemma and Dirichlet theorem. |
Let ($ L=\{ a^c|c\ is\ composite \} $) infinity amount of prime numbers from the form with pumping Lemma and Dirichlet theorem |
|automata|pumping-lemma| |
Start by showing that $L(A)$ (the language generated by the grammar if the starting symbol is $A$) is $L_A = \{ a^n b^n \mid n \geq 1 \}$. You prove this by double inclusion:
- In order to prove that $L_A \subseteq L(A)$, prove by induction on $n$ that $A \Rightarrow^* a^nb^n$.
- In order to prove that $L(A) \subse... |
> Let $L=\{ a^c \mid c \text{ is composite} \}$. Prove that $L$ is not regular using the pumping lemma. You can use Dirichlet's theorem, which states that if $(a,b) = 1$ then there are infinitely many prime numbers of the form $an+b$. |
Show that $\{ a^c \mid c \text{ is composite}\}$ is not regular using Dirichlet's theorem |
|formal-languages|pumping-lemma| |
> Let $L=\{ a^c \mid c \text{ is composite} \}$. Prove that $L$ is not regular using the pumping lemma. You can use Dirichlet's theorem, which states that if $(a,b) = 1$ then there are infinitely many prime numbers of the form $an+b$.
I am thinking about this question for a lot of days and I don't find it trivial, d... |
You can enumerate every possible configuration $c_m$ of $N$, this process takes only $O(f(n))$ space
First, lets consider the number of configuration of $N$ that runs in $f(n)$ space
If $N$ runs in $f(n)$ space, has $c$ states, $c = \vert Q \vert $, and $g$ tape symbols, $g = \vert \Gamma \vert$, then the total n... |
I have recently come across a result that showed that a given problem is in FPT when parameterized by the treewidth of a graph. However, they did this by showing that the problem is in FPT when parameterized by the treewidth of an augmented version of the graph that had treewidth of at most 2k+1 when the treewidth of t... |
Does FPT allow for doubling the parameter? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.