instruction
stringlengths
0
29.8k
⌀
|algorithms|data-structures|graphs|efficiency|shortest-path|
L1={uu(reverse)v∣u,v in{0,1}+}. that means no U no V can be epsilon. I think that this language is not regular, but i am not sure. Any ideas?
Is this language regular?
|formal-languages|regular-languages|
Consider the following language: $$ L_1=\{uu^rv \mid u,v\in\{0,1\}^+\}.$$ that means that neither $u$ nor $v$ can be $\varepsilon$. As usual $u^r$ refers to $u$ reflected. I think that this language is not regular, but i am not sure. Any ideas?
Nice question. It is irregular. Notice that this language consists of words where some nonempty prefix is an even palindrome. Intersect $L$ with $(01)^{+} (10)^{+}$. If a word of this form has a palindromic prefix: $(01)^n (10)^m = u u^R v$ and $u \neq \varepsilon$, then the center of palindrome must be between t...
To answer this question let me first point out that there are at least two levels on abstraction for the comparison numbers on a computer, the **machine-level**, and the **software level**. **Comparing numbers on the machine level** In today's computer the CPU has a rich set of instruction. These instructions inc...
[{"Id":39,"DisplayName":"Gilles"}]
[{"Id":39,"DisplayName":"Gilles"}]
Nice question. It is not regular. Notice that this language consists of words where some nonempty prefix is an even palindrome. Intersect $L$ with $(01)^{+} (10)^{+}$. If a word of this form has a palindromic prefix: $(01)^n (10)^m = u u^R v$ and $u \neq \varepsilon$, then the center of palindrome must be between...
Nice question. It is not regular. Notice that this language consists of words where some nonempty prefix is an even palindrome. Intersect $L$ with $(01)^{+} (10)^{+}$. If a word of this form has a palindromic prefix: $(01)^n (10)^m = u u^R v$ and $u \neq \varepsilon$, then the center of palindrome must be between...
Nice question. It is not regular. Notice that this language consists of words where some nonempty prefix is an even palindrome. Intersect $L$ with $(01)^{+} (10)^{+}$. If a word of this form has a palindromic prefix: $(01)^n (10)^m = u u^R v$ and $u \neq \varepsilon$, then the center of palindrome must be between...
null
This really depends on the number of zeroes and ones your dealing with on a per element basis. If your dealing with 64 or less, just convert it to a number, pop it into an array, and sort the array. 32 or less, make a blank array, convert the entry to a number, and keep track of the number of times the number pas...
The [Count-Min Sketch][1] is an awesome data structure for estimating the frequencies of different elements in a data stream. Intuitively, it works by picking a variety of hash functions, hashing each element with those hash functions, and incrementing the frequencies of various slots in various tables. To estimate t...
Why does the Count-Min Sketch require pairwise independent hash functions?
|algorithms|data-structures|randomized-algorithms|hash|
I read this question somewhere, and could not come up with an efficient answer. A string of some length has beads fixed on it at some given arbitrary distances from each other. There are $k$ different types of beads and $n$ beads in total on the string, and each bead is present atleast once. We need to find one cons...
Smallest string length to contain all types of beads
|algorithms|dynamic-programming|search-algorithms|
I believe the AD* algorithm might help you. http://www.cs.cmu.edu/~ggordon/likhachev-etal.anytime-dstar.pdf >When updated information regarding the underlying graph is received, the algorithm incrementally repairs its previous solution. The result is an approach that combines the benefits of anytime and increme...
With a little care your own suggestion can be implemented to $O(kn)$, if my idea is correct. Keep $k$ pointers, one for each colour, and a general pointer, the possible start of the segment. At each moment each of these points to the next position of its colour, that follows the segment pointer. A colour pointer is onl...
With a little care your own suggestion can be implemented to $O(kn)$, if my idea is correct. Keep $k$ pointers, one for each colour, and a general pointer, the possible start of the segment. At each moment each of these colour pointers keeps the next position of its colour, that follows the segment pointer. One col...
I believe the AD* algorithm might help you. http://www.cs.cmu.edu/~ggordon/likhachev-etal.anytime-dstar.pdf >When updated information regarding the underlying graph is received, the algorithm incrementally repairs its previous solution. The result is an approach that combines the benefits of anytime and increme...
You are right: universal hashing suffices. Pairwise independence, while stronger, is the usual method to construct a universal hash family. Also pairwise independence is contrasted in the paper with the 4-wise independence required by previous methods, such as the AMS sketch.
With a little care your own suggestion can be implemented to $O(kn)$, if my idea is correct. Keep $k$ pointers, one for each colour, and a general pointer, the possible start of the segment. At each moment each of these colour pointers keeps the next position of its colour, that follows the segment pointer. One col...
The following is an excerpt from [CLRS][1]: >$\theta(g(n))=$ { $f(n)$ : there exist positive constants $c_1$, $c_2$ and $n_0$ such that $0 \le c_1\cdot g(n) \le f(n) \le c_2\cdot g(n)$ for all $n \ge n_0$}. [Wikipedia][2] provides a similar *informal* definition without the constraint that the bound applies only ...
If $f(n) = \theta(g(n))$, do both functions bound each other for all $n$ or only sufficiently large $n$?
|complexity-theory|
You need to have a non-negative sufficiently large input size $n$ from which point on the bound holds. Because we want to be precise, don't look at the *informal* but rather at the *formal* definition on Wikipedia. That and the definition of CLRS are not conflicting. This also supports our intuition. For example, we ar...
The following is an excerpt from [CLRS][1]: >$\theta(g(n))=$ { $f(n)$ : there exist positive constants $c_1$, $c_2$ and $n_0$ such that $0 \le c_1\cdot g(n) \le f(n) \le c_2\cdot g(n)$ for all $n \ge n_0$}. [1]: http://www.amazon.ca/Introduction-Algorithms-Thomas-H-Cormen/dp/0262033844/ref=sr_1_1?s=books&ie=UTF...
You need to have a non-negative sufficiently large input size $n$ from which point on the bound holds. Because we want to be precise, don't look at the *informal* but rather at the *formal* definition on Wikipedia. That and the definition of CLRS are not conflicting. This also supports our intuition. For example, we ar...
The following is an excerpt from [CLRS][1]: >$\theta(g(n))=$ { $f(n)$ : there exist positive constants $c_1$, $c_2$ and $n_0$ such that $0 \le c_1\cdot g(n) \le f(n) \le c_2\cdot g(n)$ for all $n \ge n_0$}. Assuming $n \in \mathbb{N}$, I was unable to find $f(n)$ and $g(n)$ such that the bound does not apply for ...
The following is an excerpt from the [Wikipedia article on the Miller-Rabin primality test][1]: >It can be shown that for any odd composite $n$, at least $\frac{3}{4}$ of the bases $a$ are witnesses for the compositeness of $n$. In the Fermat primality test, if $n$ is not a Carmichael number, [at least half of ...
For every undirected edge $(u,v, weight)$ create two directed edges $(u,v, weight)$ and $(v,u,weight)$. >...but then which vertex would be the source and which vertex would be the sink? Doesn't matter.
The following is an excerpt from [CLRS][1]: >$\theta(g(n))=$ { $f(n)$ : there exist positive constants $c_1$, $c_2$ and $n_0$ such that $0 \le c_1\cdot g(n) \le f(n) \le c_2\cdot g(n)$ for all $n \ge n_0$}. Assuming $n \in \mathbb{N}$, I was unable to find $f(n)$ and $g(n)$ such that the bound does not apply for ...
[Ford-Fulkerson][1] algorithm should work for you. You can create two fake vertices viz. the source and sink. Also have a look at [Edmonds-Karp algorithm][2] which always picks the shortest path in the residual graph as opposed in any path in Ford-Fulkerson. [This][3] is a good resource. [1]: http://en.w...
[Ford-Fulkerson][1] algorithm should work for you. You can create two fake vertices viz. the source and sink. Also have a look at [Edmonds-Karp algorithm][2]. There are two variations of it: 1. One version picks the shortest path 2. Other picks a path with the maximum capacity , as opposed to Ford-Fulkerso...
So we can prove that the language say $A = \{ \langle M,w \rangle \mid \text{M is TM that accepts } w^R \text{ whenever it accepts } w \}$ is undecidable by assuming it is decidable and use that to construct a $TM$ deciding $A_{TM}$. So by contradiction $A$ is undecidable. But what if the language was $\{ \langle M,w \...
<M,w> TM M accepts w rejects w^R
|turing-machines|undecidability|
null
This language I think is not accepted by a deterministic one counter but accepted by a non det one counter : L = {a<sup>i</sup>b<sup>j</sup>c<sup>k</sup> | i=j or j=k s.t. i>=0, j>=0, k>=0} But how do prove this claim? or is it the case that they are equivalent?
is determinism = non determinism for one counter automata?
|automata|
This language I think is not accepted by a deterministic one counter but accepted by a non det one counter : $L = \{a^{i}b^{j}c^{k} \mid (i=j) \vee (j=k) \text{ such that } i\geq0, j\geq0, k\geq0\}$ But how do prove this claim? or is it the case that they are equivalent?
I stumbled upon the MSDN Best Practices for Code Review. Here is the link <http://msdn.microsoft.com/en-us/library/bb871031.aspx> Under the section of "Untrusted Inputs", i found following which I didn't understand properly. Why the following is safe? printf("%s", buffer); --------------------------------...
Handing untrusted string input in print function and avoid buffer overflow
|memory-management|
This language I think is not accepted by a deterministic one counter but accepted by a non det one counter : $L = \{a^{i}b^{j}c^{k} \mid (i=j) \vee (j=k) \text{ such that } i\geq0, j\geq0, k\geq0\}$ But how to prove this claim? or is it the case that they are equivalent?
<tt>buffer</tt> might contain a <tt>%n</tt> character, which could cause malicious memory writes. See http://www.kernel.org/doc/man-pages/online/pages/man3/sprintf.3.html or <tt>man 3 printf</tt> for more details.
All non-deterministic finite-state automata (NFA) can be represented with an equivalent deterministic finite-state automata (DFA). If you can make a NFSA that recognizes the language, you can convert it to a DFA. Have a look [here][1] for more information on how to do that. In this particular case, I believe that th...
I've heard this interview question asked a lot and I was hoping to get some opinions on what good answers might be: You have a large file 10+ GB and you want to find out which element occurs the most, what is a good way to do this? Iterating and keeping track in a map is probably not a good idea since you use a lot...
Finding the element that occurs the most in a very large file
|program-optimization|
The problem you are asking for is a well-known algorithmic problems. It is actually still open, how hard this problem exactly is. Also you should know that there are different incarnations of this problem. In contrast what you are asking for, usually only the distances are returned, whereas you are asking for the the a...
The following is an excerpt from [CLRS][1]: >$\theta(g(n))=$ { $f(n)$ : there exist positive constants $c_1$, $c_2$ and $n_0$ such that $0 \le c_1\cdot g(n) \le f(n) \le c_2\cdot g(n)$ for all $n \ge n_0$}. Assuming $n \in \mathbb{N}$, I was unable to find $f(n)$ and $g(n)$ such that the bound does not apply for ...
Who was/were the first person/people to introduce the topic of quantum complexity theory and problem classes like BQP and QMA?
Origin of quantum complexity theory
|complexity-theory|quantum-computing|history|
null
If we restrict consideration to $\mathbb{N}$ and both functions are defined on every $n \in \mathbb{N}$, then it is true that, if $f(n) \in \Theta(g(n))$, then there exists a $c$ such that $f(n) \leq cg(n)$ for all $n$, and vice versa. The proof is straightforward. If $f(n) \in O(g(n))$, then there is an $N$ and a $...
You are right: the language is accepted by a (nondeterministic) one-counter automaton. As to the deterministice case: it is not accepted by a deterministic push-down automaton. As counter automata are a special case of PDA, where we only use a single stack symbol (apart from a bottom-of-stack), it cannot be accepted...
The obvious answer is of course to keep a hash map and store the elements as you move through the file as Nejc already suggested. This is (in terms of time complexity) the optimal solution. If however, your space requirements are tight you can perform an external sort on the file and then find the longest consecutiv...
The obvious answer is of course to keep a hash map and store the elements as you move through the file as Nejc already suggested. This is (in terms of time complexity) the optimal solution. If however, your space requirements are tight you can perform an [external sort][1] on the file and then find the longest conse...
The obvious answer is of course to keep a hash map and store a counter of the occurrence of elements as you move through the file as Nejc already suggested. This is (in terms of time complexity) the optimal solution. If however, your space requirements are tight you can perform an [external sort][1] on the file and ...
If the most common element is more common than the next common element by a substantial margin, and the number of different elements is small compared to the file size, you can randomly sample a couple of elements and return the most common element in your sample.
@Raphael : Definition of trailing : Any terminal which is present at the last of a right sentential form (and not the sentence) which is derived from a non-terminal is the trailing of that non-terminal. Trailing($E$) : $E \rightarrow E + T$ --In this the trailing is '$+$' $ \rightarrow E + T * F$ [using $T \...
null
I am resuming syntax rules for a small language: $$ e_C ::= \epsilon \mid constant$$ $$ \textit{prefix-op} ::= -$$ $$ \textit{infix-op} ::= + \mid - \mid * $$ $$ e_E ::= e_C \mid \textit{prefix-op} \; e_E \mid e_E \; \textit{infix-op} \; e_E \mid \textit{function}_E (e_{E,0}, e_{E,1},\ldots) \mid \textit{specialE}$...
Present syntax rules in a more succinct way
|formal-languages|semantics|
I stumbled upon the MSDN Best Practices for Code Review. Here is the link: <http://msdn.microsoft.com/en-us/library/bb871031.aspx> Under the section of "Untrusted Inputs", i found following which I didn't understand properly. Why is the following safe? `printf("%s", buffer);` ------------------------------...
|security|memory-management|
null
This language I think is not accepted by a deterministic one counter but accepted by a non-deterministic one counter : $L = \{a^{i}b^{j}c^{k} \mid (i=j) \vee (j=k) \text{ such that } i\geq0, j\geq0, k\geq0\}$ But how to prove this claim? Or is it the case that they are equivalent?
null
I am resuming syntax rules for a small language: \begin{eqnarray*} e_C &::=& \epsilon \mid constant \\ \textit{prefix-op} &::=& - \\ \textit{infix-op} &::=& + \mid - \mid * \\ e_E &::=& e_C \mid \textit{prefix-op} \; e_E \mid e_E \; \textit{infix-op} \; e_E \mid \textit{function}_E (e_{E,0}, e_{E,1},\ldots) \mi...
One direct way of solving this problem is to make the syntax rules parameterised, as follows: \begin{eqnarray*} e_{X,Y} &::=& e_C \mid \textit{prefix-op} \; e_{X,Y} \mid e_{X,Y} \; \textit{infix-op} \; e_{X,Y} \mid Y (e_{X,Y}, e_{X,Y},\ldots) \mid X \\ \end{eqnarray*} And then to set \begin{eqnarray*} e_E &::...
The following is an excerpt from [CLRS][1]: >$\Theta(g(n))= \{ f(n) \mid \text{ $\exists c_1,c_2,n_0>0$ such that $0 \le c_1 g(n) \le f(n) \le c_2g(n)$ for all $n \ge n_0$}\}$. Assuming $n \in \mathbb{N}$, I was unable to find $f(n)$ and $g(n)$ such that the bound does not apply for all $n$. [1]: http://www...
If $f(n) = \Theta(g(n))$, do both functions bound each other for all $n$ or only sufficiently large $n$?
|asymptotics|landau-notation|
[Van Wijngaarden grammars](http://en.wikipedia.org/wiki/Van_Wijngaarden_grammar) are a way to handle this problem. It would be something like: KIND : e ; v . e KIND : e c ; prefix-op, e KIND ; e KIND, infix-op, e e; function KIND (e KIND, ",", e KIND, "," ... ) ; special KIND . (There is no "..." in t...
I read this question somewhere, and could not come up with an efficient answer. A string of some length has beads fixed on it at some given arbitrary distances from each other. There are $k$ different types of beads and $n$ beads in total on the string, and each bead is present atleast once. We need to find one cons...
If we restrict consideration to $\mathbb{N}$ and both functions are strictly positive on every $n \in \mathbb{N}$, then it is true that, if $f(n) \in \Theta(g(n))$, then there exists a $c$ such that $f(n) \leq cg(n)$ for all $n$, and vice versa. (As pointed out in the comments, if the functions can be negative, then...
**Information retrieval** is ***based on a query*** - you specify what information you need and it is returned in human understandable form. **Information extraction** is about structuring unstructured information - given some sources ***all of the (relevant) information*** is structured in a form that will be easy ...
With a little care your own suggestion can be implemented to $O(kn)$, if my idea is correct. Keep $k$ pointers, one for each colour, and a general pointer, the possible start of the segment. At each moment each of these colour pointers keeps the next position of its colour, that follows the segment pointer. One col...
> **Possible Duplicate:** > [Pumping lemma for simple finite regular languages](http://cs.stackexchange.com/questions/1847/pumping-lemma-for-simple-finite-regular-languages) <!-- End of automatically inserted text --> The pumping lemma says that for any regular language $L$, there exists a constant $p$ such that ...
{"OriginalQuestionIds":[1847],"Voters":[{"Id":157,"DisplayName":"Ran G."},{"Id":4304,"DisplayName":"Merbs"},{"Id":2205,"DisplayName":"A.Schulz"},{"Id":667,"DisplayName":"sdcvvc"},{"Id":2755,"DisplayName":"Realz Slaw"}]}
> **Possible Duplicate:** > [A puzzle related to nested loops](http://cs.stackexchange.com/questions/7008/a-puzzle-related-to-nested-loops) <!-- End of automatically inserted text --> I am trying to count the exact/total number of iterations the following nested for-loops are executed: s=0 for (i: 1 t...
{"OriginalQuestionIds":[7008],"Voters":[{"Id":3094,"DisplayName":"Bartek"},{"Id":4304,"DisplayName":"Merbs"},{"Id":2205,"DisplayName":"A.Schulz"},{"Id":667,"DisplayName":"sdcvvc"},{"Id":2755,"DisplayName":"Realz Slaw"}]}
The class **BQP** was defined by * E. Bernstein and U. Vazirani. *Quantum complexity theory*. SIAM Journal on Computing **26**, pp.&nbsp;1411-1473 (1997). The class **QMA** was defined by * A. Kitaev. *Quantum NP*. Talk at AQIP’99: Second Workshop on Algorithms in Quantum Information Processing, DePaul Univ...
I'm studying shortest paths in directed graphs currently. There are many efficient algorithms for finding the shortest path in a network, like dijkstra's or bellman-ford's. But what if the graph is dynamic? By saying dynamic I mean that we can insert or remove vertices during the execution of the program. I'm trying to...
null
I'm looking for good resources regarding **Support Vector Machines**, or suggestions where to start learning SVM. Already used references: - [Stanford ML course by Andrew Ng][2] is great place to star [2]: academicearth.org/courses/machine-learning/ - A Tutorial on Support Vector Machines for Pattern Rec...
|reference-request|machine-learning|data-mining|
null
The class [**BQP**](http://en.wikipedia.org/wiki/BQP#Definition) (see also [Complexity Zoo: BQP](http://complexity-zoo.net/zoo/wiki/Complexity_Zoo:B#bqp)) was defined by * E. Bernstein and U. Vazirani. *Quantum complexity theory*. SIAM Journal on Computing **26**, pp.&nbsp;1411-1473 (1997). The class [**QMA**](...