instruction stringlengths 0 29.8k ⌀ |
|---|
null |
null |
In compiler design, why should left recursion be eliminated in grammars? I am reading that it is because it can cause an infinite recursion, but is it not true for a right recursive grammar as well? |
Why is left recursion bad? |
|formal-grammars|compilers| |
The problem of deciding language containment in NFAs is $PSPACE$-complete. To prove this, it is easy to reduce from the universaility problem for NFAs (testing whether $L(A)=\Sigma^*$)
So, in a way, you have to determinize, but you may do so on-the-fly.
Your observation about co-NP is wrong (but nice). Such a witn... |
Operator - Generalized Symmetric Difference
-------------------------------------------
If you take binary xor and generalize it to other radices
you can do so by the absolute value of the difference of each
element in a radix vector.
However this doesn't have the same properties as the binary
symmetric diffe... |
How to construct this generalized xor without needing an extra vector? |
|discrete-mathematics|xor| |
Some sorting algorithms like count sort/insertion sort can work in O(n) while other algorithms such as quicksort require O(nlogn) time.
As I understand it, it's not always possible to use the O(n) sorting algorithms, what are those cases when they can not be used?
Thanks.
|
Sorting algorithms that work in O(n) |
|sorting| |
If you are looking for a tutorial application :
> The [Introduction to Graphical Database for Category Theory (GDCT)][1] is a research project at Mount Allison University. It allows for the
> creation, editing, and storage of finitely presented categories.
[1]: http://mathcs.mta.ca/research/rosebrugh/gdct/ |
In the comparison model, where all you are allowed to do is to compare two elements, and without further assumptions, we can prove that no sorting algorithm can do better than $O(n\log n)$.
If you want to sort in $O(n)$, you need either a stronger model, or additional assumptions.
For example, if you can bound th... |
The most common definition of `xor` is $a\oplus b=(a+b)\bmod 2$, on vertices applied to every coordinate seperately of course. In base-10 case, you have to introduce two operations: $a\oplus b=(a+b)\bmod 10$ and $a\ominus b=(a-b)\bmod 10$. (Notice that in base-2 case they coincide). Now you have
$$c=a\ominus b \quad... |
The most common definition of `xor` is $a\oplus b=(a+b)\bmod 2$, on vertices applied to every coordinate seperately of course. In base-10 case, you have to introduce two operations: $a\oplus b=(a+b)\bmod 10$ and $a\ominus b=(a-b)\bmod 10$. (Notice that in base-2 case they coincide). Now you have
$$c=a\ominus b \quad... |
null |
Some sorting algorithms like counting sort/insertion sort can work in $O(n)$ time while other algorithms such as quicksort require $O(n \log n)$ time.
As I understand it, it's not always possible to use the $O(n)$ sorting algorithms. What are those cases when they can not be used? |
When can one use a $O(n)$ time sorting algorithm? |
|algorithms|sorting| |
Von Neumann suggested his famous computer architecture as a way to simulate the laws of (classical) physics. Furthermore, it was shown that these laws can be simulated efficiently.
If you believe that the human brain works under the constraints of classical physics (also, to an extent, under quantum physics), then t... |
Given an array of size n that holds ones and zeros I need to find an index of a '1' cell that has '0' to his right (in then next cell) there could be more than one pair in a given array, any one of them is fine, the search should be in O(logn) time. Im thinking that a binary search variation is the answer but im not s... |
search algorithm help |
|sorting| |
Compilers for formal languages (ie. programming ones) deal with [context free grammars][1], These grammars are easily parsed using a stack to keep track of the already parsed phrases.
Recall that a left recursive rule of a CF grammar $G = (V,\Sigma,R,S)$ is of the form:
$\alpha \rightarrow \alpha \beta$
wi... |
Consider this rule:
example : 'a' | thingie 'b' ;
Now consider a parser trying to match a non-matching string like `'b'` to this rule. Since `'a'` doesn't match, it'll try to match `example 'b'`. But in order to do so, it has to match `example`...which is what it was trying to do in the first place. It wou... |
Consider this rule:
example : 'a' | thingie 'b' ;
Now consider a parser trying to match a non-matching string like `'b'` to this rule. Since `'a'` doesn't match, it'll try to match `example 'b'`. But in order to do so, it has to match `example`...which is what it was trying to do in the first place. It wou... |
Compilers for formal languages (ie. programming ones) deal with [context free grammars][1], These grammars are easily parsed using a stack to keep track of the already parsed phrases.
Recall that a left recursive rule of a CF grammar $G = (V,\Sigma,R,S)$ is of the form:
$\alpha \rightarrow \alpha \beta$
wi... |
{"Voters":[{"Id":4660,"DisplayName":"didierc"}]} |
Consider this rule:
example : 'a' | thingie 'b' ;
Now consider a parser trying to match a non-matching string like `'b'` to this rule. Since `'a'` doesn't match, it'll try to match `example 'b'`. But in order to do so, it has to match `example`...which is what it was trying to do in the first place. It wou... |
Consider this rule:
example : 'a' | thingie 'b' ;
Now consider a parser trying to match a non-matching string like `'b'` to this rule. Since `'a'` doesn't match, it'll try to match `example 'b'`. But in order to do so, it has to match `example`...which is what it was trying to do in the first place. It wou... |
Left recursive [grammars][3] are not necessarily a bad thing. These gramars are easily parsed using a stack to keep track of the already parsed phrases, as it is the case in [LR parser][1].
Recall that a left recursive rule of a CF grammar $G = (V,\Sigma,R,S)$ is of the form:
$\alpha \rightarrow \alpha \beta$
... |
Let's choose a different word in step 2, say $s' = 0^a1^b$, where $a$ and $b$ depend on $P$ and $a >P$ (to force an $y$ that has the form $y=0^m$).
It's important to show that for any length $m, 1\leq m \leq P$ there is no valid division $s' = xyz, y = 0^m$ (valid means it fulfils the conditions of the pumping lemma... |
{"Voters":[{"Id":4660,"DisplayName":"didierc"}]} |
Let's choose a different word in step 2, say $s' = 0^a1^b$, where $a$ and $b$ depend on $P$ and $a \geq P$ (to force an $y$ that has the form $y=0^m$).
It's important to show that for any length $m, 1\leq m \leq P$ there is no valid division $s' = xyz, y = 0^m$ (valid means it fulfils the conditions of the pumping l... |
After viewing the original question, it seems that you have an additional piece of information: you know that the first element is 1 and that the last element is 0.
This is crucial!
So indeed you can solve it with binary search: first observe that if the first element is 1 and the last is 0, there must be subsequen... |
First, as other answers have already explained, $O(3n) = O(n)$, or to put it in words, a function is $O(3n)$ if and only if it is $O(n)$. $f = O(3n)$ means that there exists a point $N$ and a factor $C_3$ such that for all $n \ge N$, $f(n) \le C_3 \cdot 3n$. Now pick $C_1 = 3 C_3$: for all $n \ge N$, $f(n) \le C_1 \cdo... |
Given an array of size n that holds ones and zeros I need to find an index of a '1' cell that has '0' to his right (in then next cell) there could be more than one pair in a given array, any one of them is fine, the search should be in O(logn) time. Im thinking that a binary search variation is the answer but im not s... |
null |
Given an array of size n that holds ones and zeros I need to find an index of a `1` cell that has `0` to his right (in then next cell) there could be more than one pair in a given array, any one of them is fine. The array is not sorted, but we do know that the first element is `1` and the last element is `0`.
The s... |
|algorithms|arrays|search-algorithms|binary-search| |
Finding a '1' cell with a '0' to its right in a binary array |
For any language L over {0,1}*,
a language L' can be defined as { a | ab ∈ L and b ∈ Σ* }
If L is decidable, is L' decidable?
I think that L' should be decidable because we can create a Turing Machine for L' that will run the decider for L on the input for L', w, accepts if it accepts otherwise enumerate all t... |
computability - decidability of a prefix language |
|computability|undecidability| |
Based on the Wikipedia page for [a formal system][1], will all programming languages be contained within the following rules?
- **A finite set of of symbols.**
(This seems obvious since the computer is a discrete machine with finite memory and therefore a finite number of ways to express a symbol.)
- **A gra... |
Are all possible programming languages a formal system? |
|formal-languages| |
its a sort of joke CS/google IQ test. its usually worth checking the semiofficial "crank" list for these types of proofs maintained by [Woeginger](http://www.win.tue.nl/~gwoegi/P-versus-NP.htm).
> At the end of April 2009, Doron Zeilberger wrote me: [...] However, you should add that this was meant as an April Fool'... |
I have some questions regarding tree search and graph search (Uninformed search) as explained in chapter 3 of the book : http://aima.cs.berkeley.edu/
As I see, the only difference between the two is that the graph search handles loops (avoids them).
First question: Do both graph search and tree search build dynam... |
Using tree search |
|artificial-intelligence|search-algorithms| |
It is a sort of joke CS or Google IQ test. It's usually worth checking the semi-official "crank" list for these types of proofs maintained by [Woeginger](http://www.win.tue.nl/~gwoegi/P-versus-NP.htm).
> At the end of April 2009, Doron Zeilberger wrote me: [...] However, you should add that this was meant as an Apri... |
Pick some self-terminating encoding of Turing machines. (That means that the encoding of one Turing machine is never a prefix of the encoding of another.) Consider the language $L$ consisting of strings $Mn$, where $M$ is an encoded Turing machine, $n$ is interpreted as a number, and $M$ halts within $n$ steps (on the ... |
For any language $L$ over $\{0,1\}^*$, a language $L'$ can be defined as $\{ a | ab \in L \text{ for some } b \in \{0,1\}^* \}$.
If $L$ is decidable, is $L'$ decidable?
I think that $L'$ should be decidable because we can create a Turing machine for $L'$ that will run the decider for $L$ on the input $w$ for $L'$... |
In general, axiomatic semantics is the nicest form of semantics, but is difficult to obtain for anything but the most simple languages, and subject of much current research. Denotational semantics is a vague term, if you mean domain theoretic semantics, then I advise against it. In general using operational semantics i... |
Questions which also contain a proof or a solution that needs to be checked for correctness and completeness. |
null |
The people doing programming language semantics try to describe programming languages in that way. Practicing programmers don't, their intuitive descriptions of the language is often fuzzy and outright contradictory (just take a look at the newbie questions and hurdles in your neighborhod freshman programming class, or... |
I read somewhere that, if $A\leq_p B$ and $B\leq_p A$, then it is said that $A\equiv_p B$. What exactly does this mean? Is it saying that both $A$ and $B$ are the exact same level of complexity? |
Anti-symmetry of polynomial time reductions |
|complexity-theory|reductions| |
Based on the Wikipedia page for [a formal system][1], will all programming languages be contained within the following rules?
- **A finite set of of symbols.**
(This seems obvious since the computer is a discrete machine with finite memory and therefore a finite number of ways to express a symbol.)
- **A gra... |
$A\equiv_p B$ is by definition $A\le_p B$ and $B\le_p A$.
It means that they are in the "exact same level of complexity", but only with respect to polynomial time reductions! For example, if $A\in LOGSPACE$ and $B\in NLOGSPACE$, then trivially $A\equiv_p B$. |
$A\equiv_p B$ is by definition $A\le_p B$ and $B\le_p A$.
It means that they are in the "exact same level of complexity", but only with respect to polynomial time reductions! For example, if $A\in LOGSPACE$ and $B\in NLOGSPACE$, then trivially $A\equiv_p B$. But clearly $A$ and $B$ are not in the "same level of comp... |
I've just finished studying recursion at university. One thing that stood out for me however was that in both the lectures and in the practical we completed, all the tasks we were asked to do could be performed faster, and in less code, using iterative means.
This was something the lecturer confirmed.
Could someb... |
Tasks in which recursion is either the fastest or only way to produce a result |
|recursion| |
There are no questions which can only be solved with recursion. This is because they can be solved with Turing machines, which don't use recursion.
The set of problems which can be solved with a TM are exactly the same as the ones which can be solved with recursion (or its formal model, the Lambda Calculus).
In p... |
I would argue that an interpreter is, in fact, one way of defining a programming language. Since there are countably many Turing Machines, we could consider the set of all programming languages to be the set of all Turing Machines which take 2 inputs, a program and some input for that program, and output the result of ... |
Both BFS and DFS take a graph and induce a subgraph of it. This subgraph has all the nodes reachable from the start node, and is a tree.
You could probably convert a graph to a tree and then use tree search, but it seems to me that the easiest way to convert a graph to a tree is, in fact, some kind of search, and it... |
The other answers provide excellent explanations of why, according to the definition of Big-O, $O(n)=O(3n)$.
As for why we actually do this in CS, it's so that we have an compact description of the efficiency of an algorithm. For example, there might be an algorithm that has an if statement, where one branch execute... |
To rationalize how asymptotic notations ignore constant factors, I usually think of it like this: asymptotic complexity isn't for comparing performance of different algorithms, it's for understanding how performance of individual algorithms scales with respect to the input size.
For instance, we say that a function ... |
null |
Of course yes, and they have mostly been describe as is.
In fact most programming language has been define using Turing Machine which aren't formal system has you've define, but they are a kind of computation's model. Then grammar and axioms are not required.
Then formal system can be view as a subset of Turi... |
Of course yes, and they have mostly been describe as is.
In fact most programming language has been define using Turing Machine which aren't formal system has you've define, but they are a kind of computation's model. Then grammar and axioms are not required.
Then formal system can be view as a subset of Turi... |
Of course yes, and they have mostly been describe as is.
In fact most programming language has been define using Turing Machine which aren't formal system has you've define, but they are a kind of computation's model, define using formal language. Then grammar or axioms or complex inference rule (as expected for f... |
[Anything that can be implemented through recursion can be implemented through iteration, and vice versa](http://en.wikipedia.org/wiki/Recursion_(computer_science)#Expressive_power). So there is no task which it is impossible to accomplish without recursion (assuming a programming language that has the usual iterative ... |
"Scripting" languages are typically *interpreted*, not compiled. That means that there will be a program called the "interpreter" for that language, which reads the programs written in the language, and executes them. You can start reading about interpreters from the Wikepedia entry:
http://en.wikipedia.org/wiki/I... |
Technically, yes, because you can make your formal system have a single axiom that says “the sequence of symbols is in the set $S$” where $S$ is the set of programs in the programming language. So this question isn't very meaningful. The notion of formal system is so general that it isn't terribly interesting in itself... |
Of course yes, and they have mostly been describe as is.
In fact most programming language has been define using Turing Machine which aren't formal system has you've define, but they are a kind of computation's model, define using formal language. Then grammar or axioms or complex inference rule (as expected for f... |
Of course yes, and they have mostly been describe as is.
In fact most programming language has been define using Turing Machine which aren't formal system has you've define, but they are a kind of computation's model, define using formal language. Then grammar or axioms or complex inference rule (as expected for f... |
null |
I was looking at the construction proof of equivalence of NFA and DFA from Sipsers text. It started by taking number of states of DFA = P(Q), where P(Q) is the set of subsets of Q.
My doubt is when we construct DFA from NFA, all the subsets may not occur in that DFA. So how could we write that the number of states ... |
Equivalence of NFA and DFA - Construction proof |
|automata|nondeterminism|automated-theorem-proving| |
It is true that this construction may result in a DFA with unreachable states. The general construction begins simply by including all possible states, then adding the appropriate transitions, so typically the resulting DFA won't be the *smallest* DFA that accepts the same language (in terms of the number of states).
... |
If you indeed follow the construction in the way you describe, then there might be states which are unreachable from the starting state. That's allowed in a DFA, though you can go ahead and remove them without affecting the operation of the automaton. |
null |
|complexity-theory|asymptotics|landau-notation| |
{"OriginalQuestionIds":[7531],"Voters":[{"Id":198,"DisplayName":"Peter Shor"},{"Id":6447,"DisplayName":"vonbrand"},{"Id":1636,"DisplayName":"Luke Mathieson"},{"Id":472,"DisplayName":"Juho"},{"Id":157,"DisplayName":"Ran G."}]} |
Functional programming employs persistence data structure and immutable objects. The question is why it is crucial to have such data structures here? I want to understand **at low level** if the data structure is not persistent what will happen? Will the program crash more often? |
Why do we use persistence data structure in functional programming? |
|programming-languages| |
Functional programming employs persistence data structures and immutable objects. The question is why it is crucial to have such data structures here? I want to understand **at low level** if the data structure is not persistent what will happen? Will the program crash more often? |
Why do we use persistence data structures in functional programming? |
null |
You should have a look at Jean-François Raskin's paper [Antichain Algorithms for Finite Automata][1].
In our experiments, the antichain-based inclusion test performed one or two orders of magnitude better than the "traditionally" approaches.
[1]: http://link.springer.com/chapter/10.1007/978-3-642-12002-2_2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.