instruction
stringlengths
0
29.8k
⌀
Is this grammar really LL(1) while not being LR(1)?
|formal-grammars|context-free|parsers|
$S \rightarrow S$, $L(G) = \{\}$ **LL(1) analysis:** We estabilish $FIRST(S)$ to be empty and $FOLLOW(S)$ to be $\{\$\}$. $FIRST(S)$ doesn't contain ε, so the parse table looks like this: +---+---+ | | $ | +---+---+ | S | | +---+---+ and correctly rejects any input inclu...
I have a language which is made out of and has a grammar only operating on well parenthesized words or words of one symbol. I want to know if the problem of belonging to this language is decidable. **Example.** Consider the following grammar: $$a \to a(aa) \\ a \to b \\a (a(a(ab))) \to b$$ I'll denote by $L(x)$ th...
About complexity of a language
|formal-languages|computability|
This formalization takes Dijkstra's algorithm and formalizes it as a network flow problem. In the network flow problem, $b_i$ represents the amount of flow that enters or leaves a network at vertex $i\in V$. If $b_i > 0$ we say that $i$ is a source supplying $b_i$ units of flow. If $b_i < 0$ we say that $i$ is a si...
null
My thoughts, without formal proofs. They are applicable only to your specific grammar. Obviously, the first two productions $a\to a(aa)$ and $a\to b$ are no problem to handle. The last production $a(a(a(ab))) \to b$ can be used to shorten the string/tree. But note that it can only be applied to trees of a specific f...
(I completely removed the previous answer, which was applicable only to this particular example). Your grammars seem to be known as *ground term rewriting systems* nowadays. They are rather old. Theu might be introduced by W.S. Brainard: Tree generating regular systems. Inform. and Control 14 (1969) 217-231.
(I completely removed the previous answer, which was applicable only to this particular example). Your grammars seem to be known as *ground term rewriting systems* nowadays. They are rather old. They might be introduced by W.S. Brainard: Tree generating regular systems. Inform. and Control 14 (1969) 217-231. C...
I am particularly interested in solutions to the problem that encapsulated search can depend on the order of evaluation. According to [1], encapsulated search in PAKCS depends on the order of evaluation, while in MCC, it does not, but using it requires knowledge of the compiler implementation and it does not follow ...
What is the state of the art in encapsulated search in functional logic programming?
|nondeterminism|functional-programming|logic-programming|
I found the algorithm for finding the negative cycle in a graph after running Bellman-Ford. The algorithm is to perform another relax iteration over all the edges. Than if we find an edge to relax we stop and start to follow it parent vertex starting from V that u is its parent until we close a cycle. Im having lit...
bellman ford algorthm and negative cycle proof
|algorithms|
How can someone find what type of grammar for a given programming language? Formerly I'm looking for a grammar type for most popular programming languages: C, C++, C#, Java, List, OCaml, Haskell etc.
Finding the grammar type of the programming language
|formal-grammars|programming-languages|
Since the development of ALGOL60 one realised that a systematic approach to define the language was necessary. Backus-Naur-form was developed, meaning that most programming languages are basically context-free. I say basically, because some parts of the language cannot be defined in that way. As an example, the decl...
Prove that the problem of determining if graph is bipartite is computationally equivalent under log-space reductions to $s$-$t$ undirected connectivity. Problem of $s$-$t$ undirected connectivity is the following given an undirected graph $G = (V, E)$ and two designated vertices, $s$ and $t$, determine whether ther...
Bipartite Problem is Log-Space Reducible To $s$-$t$ Undirected Connectivity
|complexity-theory|space-complexity|
null
Given a directed graph G , weights, s source vertex and d[v] for each vertex in the graph (the distance from s to v) I need to find an algorithm that builds the shortest paths tree. I was thinking of going on edges by BFS but than how can I know which edge should be in the tree and how to check that the d[v] for eac...
shortest paths tree
|algorithms|
If I understand your question correctly then [Minimum Spanning Tree][1] is what are you looking for. Thre are multiple algorithms already developed like [Dijkstra's algorithm][2] or [Bellman-Ford algorithm][3]. The problem you face is also well described on [Wikipedia][4]. Maybe there is something specific abo...
Given a directed graph G , weights, s source vertex and d[v] for each vertex in the graph (the distance from s to v) I need to find an algorithm that builds the shortest paths graph. I was thinking of going on edges by BFS but than how can I know which edge should be in the tree and how to check that the d[v] for ea...
Shortest paths graph
Thre are multiple algorithms already developed like [Dijkstra's algorithm][2], [Bellman-Ford algorithm][3] or [A* search algorithm][4]. The problem you face is also well described on [Wikipedia][1]. Maybe there is something specific about your assignment like memory or time complexity? [1]: http://en.wikiped...
Here are some ideas on how to reduce checking bipartiteness to undirected *non*-connectivity: 1. A graph is bipartite iff it has no odd cycles. 1. Suppose we guess that vertex $v$ participates in a cycle of length $2k+1$. Using a layered graph, we can check whether it is the case using undirected connectivity. 1. ...
Given a directed graph $G$, edge weights for each edge, source vertex $s$ and $d[v]$ for each vertex in the graph (the distance from $s$ to $v$), I need to find an algorithm that builds the shortest paths graph. I was thinking of going on edges by BFS, but then how can I know which edge should be in the tree and how...
null
As has been pointed out, there are well known shortest path algorithms. But your problem already has most of the information. Specifically, you already know the shortest path distances $d[v]$ from $s$ for each node $v$. In such a case, you can use a much better algorithm. By a "shortest paths graph", I think you mea...
null
I don't think this is the right place for such questions, and maybe [Stackoverflow][1] or [programming puzzles and code golf][2] may be better suited. However, I'll try to answer the question nevertheless. I do not think your code has anything to do with equality of two numbers. Your code can be separated into t...
**[Counter machines][1]** with two or more counters are typically shown to be equivalent to Turing machines in courses on the theory of computation. However, I have not seen a formal analysis of what languages can be recognized by a one-counter machine. Are these languages equivalent to the context-free languages (pe...
What languages are recognized by one-counter machines?
|computability|automata|
I don't think this is the right place for such questions, and maybe [Stackoverflow][1] or [programming puzzles and code golf][2] may be better suited. However, I'll try to answer the question nevertheless. I do not think your code has anything to do with equality of two numbers. Your code can be separated into t...
**[Counter machines][1]** with two or more counters are typically shown to be equivalent to Turing machines in courses on the theory of computation. However, I have not seen a formal analysis of which languages can be recognized by a one-counter machine. Are these languages equivalent to the context-free languages (p...
Which languages are recognized by one-counter machines?
null
**[Counter machines][1]** with two or more counters are typically shown to be equivalent to Turing machines in courses on the theory of computation. However, I have not seen a formal analysis of which languages can be recognized by a one-counter machine. Are these languages equivalent to the context-free languages (p...
null
A one counter automata is a push down automata with only one symbol allowed on the stack (plus a fixed bottom symbol). Languages recognized by one counter automata form a proper subset of the context free languages. For example a 1-counter automata can recognize the language $\{a^nb^n\}$ which is not regular, but ...
A one counter automata is a push down automata with only one symbol allowed on the stack (plus a fixed bottom symbol). Languages recognized by one counter automata form a proper subset of the context free languages. For example a 1-counter automata can recognize the language $\{a^nb^n\}$ which is not regular, but ca...
A one counter automata is a push down automata with only one symbol allowed on the stack (plus a fixed bottom symbol). Languages recognized by one counter automata form a proper subset of the context free languages. For example a 1-counter automata can recognize the language $\{a^nb^n\}$ which is not regular, but ca...
I found the algorithm for finding the negative cycle in a graph after running [Bellman-Ford algorithm][1]. The algorithm is to perform another relax iteration over all the edges. Than if we find an edge to relax we stop and start to follow it parent vertex starting from $V$ that $u$ is its parent until we close a c...
Bellman-Ford algorthm and negative cycle proof
|algorithms|graphs|
null
null
Hardness of finding a true or a false assignment into a generic boolean formula?
null
The book I have been consulting starts with the assumption: "let $G$ be a grammar without useless symbols". I could not immediately see where that is necessary in the analysis, but obviously your variables are useless, they do not generate terminal strings. You are right, I could find no explicit note of that fact i...
{"Voters":[{"Id":4486,"DisplayName":"Dadsetani"}]}
this grammar is equivalent with $$ \begin{align} S \rightarrow &0A1B\mid 1B \\ A \rightarrow & 0A \mid \varepsilon \\ B \rightarrow & 0B \mid 1B \mid \varepsilon \\ \end{align} $$ and so like a simple grammar we can show this grammar is not ambiguous. p.s. any simple grammar is unambiguous.
{"Voters":[{"Id":4486,"DisplayName":"Dadsetani"}]}
null
A one counter automata is a push down automata with only one symbol allowed on the stack (plus a fixed bottom symbol). Languages recognized by one counter automata form a proper subset of the context free languages. For example a 1-counter automata can recognize the language $\{a^nb^n\}$ which is not regular, but ca...
A multiset is an unordered collection of elements where elements may repeat any number of times. The size of a multiset is the number of elements in it counting repetitions. (a) What is the number of multisets of size 4 that can be constructed from n distinct elements so that at least one element occurs exactly twi...
multisets of a given set
|combinatorics|sets|
Here is one way to go about your part (a): There are four places to be filled in the multiset using the $n$ distinct elements. Atleast one element has to occur exactly twice. That would leave 2 more places in the multiset. This mean, *atmost* two elements can occur exactly twice. We can thus divide this into 2 mutua...
A multiset is an unordered collection of elements where elements may repeat any number of times. The size of a multiset is the number of elements in it counting repetitions. (a) What is the number of multisets of size 4 that can be constructed from n distinct elements so that at least one element occurs exactly t...
null
Here is one way to go about your part (a): There are four places to be filled in the multiset using the $n$ distinct elements. Atleast one element has to occur exactly twice. That would leave 2 more places in the multiset. This means, *atmost* two elements can occur exactly twice. We can thus divide this into 2 mutu...
A one counter automata is a push down automata with only one symbol allowed on the stack (plus a fixed bottom symbol). Languages recognized by one counter automata form a proper subset of the context free languages. For example a 1-counter automata can recognize the language $\{a^nb^n\}$ which is not regular, but ca...
A multiset is an unordered collection of elements where elements may repeat any number of times. The size of a multiset is the number of elements in it counting repetitions. (a) What is the number of multisets of size $4$ that can be constructed from $n$ distinct elements so that at least one element occurs exact...
Multisets of a given set
This problem is as hard as comparison sorting, given `n` input number sort them. You can make interval set from input number set $S$ (w.l.o.g suppose input numbers are in $Z^+$) as follow: $ \Gamma = \{(a,b) \mid a\in S \wedge b=\max_{t\in S} \{2\cdot t - a + 1 \} \}$ Above transformation can be done in $O(n)$...
There is a version of your question for which unparsing is easy and can be done in linear time. However, I'm not entirely sure if your question pertains to this specific version of unparsing, so I'll look at that first. You say in your question over at StackOverflow that your AST looks like "AnyObject -> AnyObject -...
I've just consulted [a parsing book][1], and it indeed requires that $S \Rightarrow^+ S$ be impossible, if $S$ is the starting symbol, before a grammar is considered $LR(k)$. As you said yourself, this is not required for a grammar to be $LL(k)$. Usually, it is implicitly assumed grammars 'behave' when we make state...
In their book [*Randomized Algorithms*,][1] Motwani and Raghavan open the introduction with a description of their RandQS function -- Randomized quicksort -- where the pivot, used for partitioning the set into two parts, is chosen at random. I have been racking my (admittedly somewhat underpowered) brains over this ...
What is the advantage of Randomized Quicksort?
|algorithm-analysis|sorting|randomized-algorithms|
If the input array is distributed uniformly at random then (as you noted) there is no difference between always picking an element at a fixed position (for example the middle one as you suggest) or picking an element chosen at random. If however your input array is not really in random order (which happens to be the...
As noted by Jernej, the assumption that the all permutations of the input are equally likely does not always hold in reality. The first idea might be to permute the input array. This would work, but is easier to analyze the situation where a pivot is chosen at random. This is also known as *random sampling*.
If the input array is distributed uniformly at random then (as you noted) there is no difference between always picking an element at a fixed position (for example the middle one as you suggest) or picking an element chosen at random. If however your input array is not really in random order (which happens to be the...
Not really. You should read a few books. Perhaps we can recommend some. That said, a language is recursive if there is a Turing machine than can always reply "yes" or "no" if a given string is part of this language. If we lift this requirement to merely say "yes" for strings of the language (it can run forever if it...
I've came across many definitions of recursive and recursively enumerable languages. But I couldn't quite understand what they are . Can some one please tell me what they are in simple words Thanks in advance
recursive and recursively enumerable language definition for a layman
|untagged|
i have read few algorithms for LR(k) parser, in which their is a frequent mention of selecting a handle from the grammar given. eg : one document said - *"the essence of LR parsing is identifying the handle on top of stack"* please help
what are handles in parsing?
|untagged|
$L$ is a regular language, so you have a DFA $M$ for it. First remove every “dead” state in $M$, i.e. every state that cannot lead to an accepting state. Make every state in $M$ an accepting state, and make a new start state that $\epsilon$-branches to every state in $M$. The resulting NFA $M'$ recognizes $P$, because:...
I need some help with the following problem: $L$ - regular language and i have to prove that the language $P$ = {$\alpha$| $\beta\alpha\gamma \in L$, $\beta,\gamma \in (A)^*$} is regular. In other words $P$ is the language of all parts of words from $L$. Thanks a lot!
Regularity of “middles” of words from regular language
|untagged|
Counter automata were much studied in the ancient formal language past, in the context of AFA and AFL theory (abstract families of automata & languages) by US and French teams (Ginsberg, Greibach, ... , Nivat, Berstel, ...) Counter automata are typically defined as finite state automata equipped with external memory...
|regular-languages|finite-automata|