instruction stringlengths 0 29.8k ⌀ |
|---|
Thanks to rici and D.W. for pointing out a very practical example of a LR(1) grammar that can not be expressed as an LL(1) grammar.
They've provided the example language $\{a^ib^j\mid i\ge j\}$, which shows why "if then optional-else" is not in $LL(k)$ for any $k$. The example language has at the same or more number... |
Thanks to rici and D.W. for pointing out a very practical example of a LR(1) grammar that can not be expressed as an LL(1) grammar.
They've provided the example language $\{a^ib^j\mid i\ge j\}$, which shows why "if then optional-else" is not in $LL(k)$ for any $k$. The example language has at the same or more number... |
I have to show that given $f:\mathbb{N}\rightarrow\mathbb{N}$ the function that returns the numbers of $6$ in the input (for esample $f(436546)=2$) is primitive recursive.
The exercise says to assume that the functions $rem(m,n)$ and $div(m,n)$ which returns the reminter and the quotient are recursive primitive (rp fr... |
Show that the number of 6 in a natural number is recursive primitive |
|complexity-theory| |
|recursion| |
I have to show that given $f:\mathbb{N}\rightarrow\mathbb{N}$ the function that returns the numbers of $6$ in the input (for esample $f(436546)=2$) is primitive recursive.
The exercise says to assume that the functions $rem(m,n)$ and $div(m,n)$ which returns the reminter and the quotient are recursive primitive (rp fr... |
null |
> show that $L=\{a^*\}\cup\{b^ja^{n^2}|0<j,1\leq n \}$
>Holds the pumping lemma for context-free languages
the problem is that I know how to refute with pumping lemma that a language is **not context-free**.
but I don't know how to prove Language holds the pumping lemma -> **is a context-free** lang.
|
null |
**Definitions:**
1.
$$NP = \{S \: \mid \: \text{Exists A a polynomial, non-deterministic algorithm s.t A decides S} \}$$ Where a polynomial non-deterministic algorithm, is an algorithm that it's runtime is bounded by $p$ some polynomial, and may behave differently from run to run.
2. $$P \setminus poly = ... |
Why can't you randomize an advice string to show that $P \setminus poly \subseteq NP$ |
|complexity-theory| |
Printing an array using recursion is much slower as compared to printing an array using iteration. Why? Is iteration always faster than recursion? |
Printing an array using recursion |
|optimization| |
prove this language verifies the conclusion of the pumping lemma
> show that $L=\{a^*\}\cup\{b^ja^{n^2}|0<j,1\leq n \}$
>Holds the pumping lemma for context-free languages
the problem is that I know how to refute with pumping lemma that a language is **not context-free**.
but I don't know how to prove Languag... |
It takes most (when not all) compilers more time to call a method, then to jump back with the programmcounter. (The number that indicates which line gets executed.) |
It takes most (when not all) compilers more time to call a function, then to jump back with the programmcounter. (The number that indicates which line gets executed.)
When a function gets executed, its parameters and return-adress have to be registered on the stack. |
null |
given a graph G = (V, E) where
1. G is directed: $ \forall \ e \in E : e \ has \ a \ direction $
2. G is acyclic (no cycles): $ \forall \ paths \ \{v_1, \dots , v_n\} \in G : v_1 \ != v_n $
3. indegree >= outdegree: $ \forall \ v \in V : d^{-1}(v) >= d^{+1}(v) $
4. If indegree is 0, outdegree is <= 1: $ \forall \ v... |
DAG graph where indegree >= outdegree and indegree = 0 => outdegree <= 1, cover all vertex with min amount of paths |
|algorithms|graphs| |
When you make an informal statement like "Is it provably true/false that for a program, there exists a proof whether it halts or not?", the "a" article is interpreted as a universal quantifier: if we increase the formality of the question it becomes: for every program P, is there a halting proof?
And this is what th... |
Software engineers competent in C and the x86 language will verify that when H(P,P) correctly emulates its input with an x86 emulator that this emulation would never stop running. This provides the basis for H(P,P) to correctly reject its input as non-halting.
> For any program H that might determine if programs h... |
Software engineers competent in C and the x86 language will verify that when H(P,P) correctly emulates its input with an x86 emulator that this emulation would never stop running. This provides the basis for H(P,P) to correctly reject its input as non-halting.
> For any program H that might determine if programs h... |
This answer includes some clarification and an answer. The figure in the question is from [here](https://bmcbioinformatics.biomedcentral.com/articles/10.1186/1471-2105-15-228). Some clarifications regarding the terms:
1. Two DAGs are equivalent iff they have the same skeletons and the same v-structures. Each equival... |
null |
Suppose i have a CNF formula. If i negate the CNF formula, then i obtain DNF formula. However, i can't find anywhere on internet that mention the time complexity. What is the time complexity of negating a CNF formula and converting it to DNF formula? |
Time complexity of negating a CNF formula |
|algorithms|time-complexity|boolean-algebra| |
**Definitions:**
1.
$$\mathsf{NP} = \{S \: \mid \: \text{Exists a polynomial, non-deterministic algorithm $A$ s.t. $A$ decides $S$} \}$$ Where a polynomial non-deterministic algorithm, is an algorithm that it's runtime is bounded by $p$ some polynomial, and may behave differently from run to run.
2. $$\ma... |
Why can't you randomize an advice string to show that $P/poly \subseteq NP$ |
Consider the following functions with advice:
$$ f(a,x) = a. $$
(The advice $a$ is one bit.)
The function $f$ is computable in polynomial time, and this shows that any language of the form $\{ x : |x| \in S \}$ belongs to $\mathsf{P/poly}$. If we choose $S$ to be some uncomputable set, then the corresponding langu... |
null |
This answer includes some clarification and an answer. The figure in the question is from [here](https://bmcbioinformatics.biomedcentral.com/articles/10.1186/1471-2105-15-228). Some clarifications regarding the terms:
1. Two DAGs are equivalent iff they have the same skeletons and the same v-structures. Each equival... |
# Generating numbers with $k$ bits set for a poker simulation
## Context
I'm trying to generate all possible [Texas Hold'em](https://en.wikipedia.org/wiki/Texas_hold_'em) games for $p$ players, which means there will be at most $2 \cdot p + 5$ cards at play.
To make things a little bit easier, I figured that I... |
Generating the n-th number with k bits set, is it possible? |
|algorithms|reductions|dynamic-programming|combinatorics| |
null |
This is called *Enumerative Coding* and was introduced by Tom Cover. Consider a word $W$ that is $n$ bits long, where the one bits are in locations $x_k, \ldots, x_1$ with $x_k>x_{k-1}>\cdots>x_1$ and the locations are labelled from $0$ to $n-1.$
The position of this word in the lexicographic ordering of all word... |
Here is a recursive function for your problem:
\begin{align*}
& \mathrm{count6}(n) = \mathrm{cond}(\mathrm{eq}(n, 0), 0,\\
& \quad \mathrm{add}(\\
& \quad \quad \mathrm{cond}(\mathrm{eq}(\mathrm{rem}(n, 10), 6), 1, 0), \mathrm{count6}(\mathrm{div}(n, 10)))
\end{align*}
$\mathrm{eq}$ is defined as:
$$
\mathrm{... |
$\def\NT#1{{\langle\it #1\rangle}}\def\T#1{{\tt#1}}$
The canonical example of an $LR(1)$ language which is not $LL(k)$ for any $k$ is $L_{\ge} = \{a^i b^j\mid i\ge j\}$. It's easy to show that the language is $LR(1)$ since it has an $LR(1)$ grammar (in fact, an $SLR(1)$ grammar):
$$\begin{align}L_{\ge}&\to M\\L_{\g... |
$\def\NT#1{{\langle\it #1\rangle}}\def\T#1{{\tt#1}}$
The canonical example of an $LR(1)$ language which is not $LL(k)$ for any $k$ is $L_{\ge} = \{a^i b^j\mid i\ge j\}$. It's easy to show that the language is $LR(1)$ since it has an $LR(1)$ grammar (in fact, an $SLR(1)$ grammar):
$$\begin{align}L_{\ge}&\to M\\L_{\g... |
We shall asymptotically solve $\color{blue}{ f(2n) = f(n)·\log(f(n))·2^c }$ for any $c∈ℝ$ as $n → ∞$ (where $\log = \log_2$).
$
\def\lfrac#1#2{{\large\frac{#1}{#2}}}
$
~ ~ ~
Note that $\log\log(2n) = \log(\log(n)+1)$ $= \log\log(n)+\lfrac{r}{\log(n)}+\cdots$ where $r = \lfrac1{\ln(2)}$. (Omitted terms are asym... |
$\def\NT#1{{\langle\it #1\rangle}}\def\T#1{{\tt#1}}$
The canonical example of an $LR(1)$ language which is not $LL(k)$ for any $k$ is $L_{\ge} = \{a^i b^j\mid i\ge j\}$. It's easy to show that the language is $LR(1)$ since it has an $LR(1)$ grammar (in fact, an $SLR(1)$ grammar):
$$\begin{align}L_{\ge}&\to M\\L_{\g... |
null |
null |
$\def\NT#1{{\langle\it #1\rangle}}\def\T#1{{\tt#1}}$
The canonical example of an $LR(1)$ language which is not $LL(k)$ for any $k$ is $L_{\ge} = \{a^i b^j\mid i\ge j\}$. It's easy to show that the language is $LR(1)$ since it has an $LR(1)$ grammar (in fact, an $SLR(1)$ grammar):
$$\begin{align}L_{\ge}&\to M\\L_{\g... |
null |
null |
I've learned some basics about P and NP. Please excuse if the following is not very precise.
I've read that NP-complete problems are the hardest problems in NP. (Is that correct?)
But now I'm wondering if P problems have polynomial runtime, and assuming P=NP for a moment, how can polynomial runtime problems ever ... |
How could NP-complete problems be in P? |
|np-complete|p-vs-np| |
Here is a recursive function for your problem:
\begin{align*}
& \mathrm{count6}(n) = \mathrm{cond}(\mathrm{eq}(n, 0), 0,\\
& \quad \mathrm{add}(\\
& \quad \quad \mathrm{cond}(\mathrm{eq}(\mathrm{rem}(n, 10), 6), 1, 0), \mathrm{count6}(\mathrm{div}(n, 10)))
\end{align*}
$\mathrm{eq}$ is defined as:
$$
\mathrm{... |
Consider the code
scanf("%d", &size); malloc(size);
How will the compiler calculate the amount of memory ?
----------
The fact is that a default size is allocated for the heap and the stack, and these might be increased on demand at run-time, depending on the memory manager. |
$NP$-complete problems are the hardest problems in $NP$ with regard to the time required to solve them. Despite more than 50 years of research, nobody was able to design a polynomial time algorithm to solve one of them (nor to prove a supra-polynomial lower bound either). Actually, solving one of them also implies solv... |
If a problem X is NP-complete, that means "I can solve any problem in NP by converting it into an instance of X that has the same YES or NO answer in polynomial time, and solving that instance.". We are very, very generous with "polynomial" factors here. n^2 and n^1000 are considered equal _in this context_, because it... |
I've learned some basics about P and NP. Please excuse if the following is not very precise.
I've read that NP-complete problems are the hardest problems in NP. (Is that correct?)
But now I'm wondering if P problems have polynomial runtime, and assuming P=NP for a moment, how can polynomial runtime problems ever ... |
One can never prove a language to be context-free with the use of pumping lemma alone. The pumping lemma for context-free languages states a property that is necessary but not sufficient for context-free languages. There are no context-free languages that lack a context-free pumping property, but there are languages th... |
We shall asymptotically solve $\color{blue}{ f(2n) = f(n)·\log(f(n))·2^c }$ for any $c∈ℝ$ as $n → ∞$ (where $\log = \log_2$).
$
\def\lfrac#1#2{{\large\frac{#1}{#2}}}
$
~ ~ ~
Note that $\log\log(2n) = \log(\log(n)+1)$ $= \log\log(n)+\lfrac{r}{\log(n)}+\cdots$ where $r = \lfrac1{\ln(2)}$. (Omitted terms are asym... |
I'm struggling with this question. I would appreciate a detailed solution as it would help me better understand the subject.
Convert the following Context Free grammar into a Regular Grammar:\
S -> aSb | A\
A -> bA | a |
CFG to RG Conversion |
|regular-languages|context-free| |
$NP$-complete problems are the hardest problems in $NP$ with regard to the time required to solve them. Despite more than 50 years of research, nobody was able to design a polynomial time algorithm to solve one of them (nor to prove a supra-polynomial lower bound either). Actually, solving one of them in polynomial tim... |
No, you can't convert context free grammar into regular grammar. Because CFG is $Type-2$ grammar which has less restriction than $Type-3$ RG grammar. CFG generate more complex languages that RG can never do.
But remember every $Type-3$ RG grammar is also satisfied conditions of $Type-2$, $Type-1$, $Type-0$ gramma... |
null |
No, you can't convert context free grammar into regular grammar in general. Because CFG is $Type-2$ grammar which has less restriction than $Type-3$ RG grammar. CFG generate more complex languages that RG can never do.
**But one thing** when CFG generate a language which is regular then you must write equivalent RG... |
No, you can't convert context free grammar into regular grammar in general. Because CFG is $Type-2$ grammar which has less restriction than $Type-3$ RG grammar. CFG generate more complex languages that RG can never do.
**But one thing** when CFG generate a language which is regular then you must write equivalent RG... |
No, you can't convert context free grammar into regular grammar **in general**. Because CFG is $Type-2$ grammar which has less restriction than $Type-3$ RG grammar. CFG generate more complex languages that RG can never do.
**But one thing** when CFG generate a language which is regular then you must write equivalen... |
null |
When you look up a value in a hash table, the minimum
cost is: One calculation of the values hash code. One calculation of a location where the value would likely to be stored if it was present in the hash table. One comparison of two hash codes. If they match, one comparison of values.
Additional cost is: Checki... |
I believe this is true and I have given a simple proof of this:
If A is Turing-reducible to B then there exists a Turing machine with oracle for B that decides A, because B is Turing-recognizable then by using the oracle for B we can decide A and therefore A is Turing recognizable. |
If A is Turing-reducible to B and B is Turing recognizable then A is Turing recognizable |
|turing-machines|turing-recognizable| |
The statement is false.
Consider the language $H$ of the halting problem and let $H'$ be its complement.
$H'$ is Turing reducible to $H$ and $H$ is recognizable, however $H'$ is not recognizable (if $H'$ were recognizable then $H$ would be decidable). |
This is basically the Church-Turing hypothesis.
We know there are programs P such that no program X can prove that P halts, or that P doesn't halt. That's not what you asked. You asked "can we prove..." The Church-Turing hypothesis claims that everything "we" can do, some program could do. If the Church-Turing hypo... |
null |
I have implemented an indexed linked list that runs (under mild assumptions) all single-element access operations in $\mathcal{O}(\sqrt{n})$ time. The description is [here](https://coderodde.github.io/weblog/#meill) and Java implementation is [here](https://github.com/coderodde/IndexedLinkedList/blob/main/src/main/java... |
How to analyze the amortized running time of an indexed linked list using potential method |
|heuristics|linked-lists|succinct-data-structures| |
No, you can't convert context free grammar into regular grammar **in general**. Because CFG is $Type-2$ grammar which has less restriction than $Type-3$ RG grammar. CFG generate more complex languages that RG can never do.
**But one thing** when CFG generate a language which is regular then you must write equivalen... |
I have implemented an indexed linked list that runs (under mild assumptions) all single-element access operations in $\mathcal{O}(\sqrt{n})$ time. The description is [here](https://coderodde.github.io/weblog/#meill) and Java implementation is [here](https://github.com/coderodde/IndexedLinkedList/blob/main/src/main/java... |
There is no known regularity in the primes, and for small numbers (such as 8 bits naturals), the best is to implement them as a table.
If you want an instant answer, one comparator per prime can do. Otherwise, binary search can be implemented in hardware, possibly storing a binary trie. Or simply an array of bits, o... |
null |
I have implemented an indexed linked list that runs (under mild assumptions) all single-element access operations in $\mathcal{O}(\sqrt{n})$ time. The description is [here](https://coderodde.github.io/weblog/#meill) and Java implementation is [here](https://github.com/coderodde/IndexedLinkedList/blob/main/src/main/java... |
Levels by levels, the indexes of a binary heap are
$$0\\1\ \ \ \ \ \ \ \ \ \ \ \ \ 2\\3\ \ \ \ \ \ 4\ \ \ \ \ \ 5\ \ \ \ \ \ 6\\7\ 8\ 9\ 10\,11\,12\,13\,14\\\cdots$$
and it is rather clear that the sons of $n$ are $2n+1$ and $2n+2$.
By inversion, the father of $m$ is one of $\dfrac{m-1}2$ or $\dfrac{m-2}2$, an... |
Assume in a distributed network, where the nodes are not trusted and are identified by their public keys, we intend to select one of them in a random process. In such a situation, all of the nodes have the same chances to be elected.
Since the system is not centralized and there is no trusted server performing the e... |
How to select a random node when nodes are untrusted in a distributed network? |
|distributed-systems|randomness|random-walks| |
null |
Consider an arbitrary sequence of $m$ MAKESET operations, followed by $u$ UNION operations, followed
by $f$ FIND operations, and let $n = m + u + f$ in a disjoint set union data structure. Prove that if we use union by rank and FIND with
path compression, all $n$ operations are executed in $O(n)$ time.
I'm not sur... |
Disjoint Set union complexity when makesets, unions and finds follow a certain order |
|time-complexity|disjoint-sets| |
I have implemented an indexed linked list that runs (under mild assumptions) all single-element access operations in $\mathcal{O}(\sqrt{n})$ time. The description is [here](https://coderodde.github.io/weblog/#meill) and Java implementation is [here](https://github.com/coderodde/IndexedLinkedList/blob/main/src/main/java... |
The $m$ makeset and the $u$ union operations are executed in time $O(m+u)$, so we only need to argue about the find operations.
We say that a node is $u$ "touched" by a find($x$) operation if it is an internal node of of the unique path between $x$ and the root of the tree containing $x$ when the operation is perfor... |
{"Voters":[{"Id":6759,"DisplayName":"Steven"}]} |
Normally, when working with dictionaries, we expect around O(1) complexity when we go to retrieve a value given the key (and when we insert). I work in Python, but this might apply to any dynamic typed language. I have been working with dictionaries where the keys are frozensets, which are just sets that are hashable ... |
Dictionary with sets as keys where lookup can be set intersection |
|data-structures|sets|dictionaries| |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.