instruction stringlengths 0 29.8k ⌀ |
|---|
|computability| |
I am doing some excercises to train myself in computability.
There is one that I am not able to solve, here it is.
Consider the following transformation associated to an extended WHILE program:
For all $x \in \mathbb{N}$,
$\begin{cases}
A f(x) = x \cdot f((x+3)/2) & \text{if \(x\) is odd} \\
A f(x) = f(x+... |
No left recursion in an LL(1) grammar.
A grammar with A → αβ1 | αβ2 is not LL(1).
If any entry is multiply defined then G is not
LL(1). Possible reasons:
If G is ambiguous
If G is left recursive
If G is not left-factored
Grammar is not LL(1) |
Suppose $f$ is a fixpoint of $A$. First,
$$
f(0) = f(1) = f(2) = f(3) = 3f(3),
$$
and so $f(0) = f(1) = f(2) = f(3) = 0$. Second,
$$
f(5) = 5f(4) = 5f(5),
$$
and so $f(4) = f(5) = 0$. Third, if $n = 4m+3 \geq 7$ then $$f(n) = n f(2m+3),$$ while if $n = 4m+1 \geq 9$ then $$f(n) = n f(2m+2) = nf(2m+3).$$ In both ... |
A short answer: no [but this is only an opinion]
Dont go to Category Theory or any other theoretical domain to become good in Haskell. Learn functional programming techniques, such as tail recursion, map, reduce, and others. Read as much code as you can. Implement as many ideas as you can. If you have issues, read ... |
I have a tree of foods, which I'd like to search to find relevant nodes. What's the best way to rank the results?
Here's an example sub-set after a search for "apple":
|-- apple pie
|-+ apples
| |-- cooking
| |-+ eating
| |-- average
| |-- Granny Smith
| |-- Golden Deli... |
How to rank search results of short string lists |
|search-algorithms| |
null |
Echoing @AJed advice, I recommend to turn your statement
I want to learn category theory so I can become better at Haskell.
on its head: learn Haskell, building on your programming intuition. Once you are an FP guru, it might be easier to pick up category theory (if you still care).
Category theory is sim... |
Q: **Consider a demand-paging system with a paging disk that has an average access and transfer time of 20 milliseconds. Addresses are translated through a page table in main memory, with an access time of 1 microsecond per memory access. Thus, each memory reference through the page table takes two accesses. To improve... |
Effective Acces time in Demand Paging system with Associative memory |
|paging| |
Although i dont really know how a result is better. I guess what you are doing is fine (And perhaps the best possibly you can get). Just one note to be more precise, you should be ranking a node $u$ based on the size of the subtree rooted at $u$ (not on the number of leaves in that subtree, or children of $u$). This is... |
Consider the following problem:
>Let a *$k$-wheel* be defined as an indexed circularly linked list of $k$ integers. For example…
>>{3, 4, 9, -1, 6}
>…is a 5-wheel with 3 at position 0, 4 at position 1, and so on. A wheel supports the operation of rotation, so that a one-step rotation would turn the above whe... |
sum of like indices in circular lists |
|algorithms| |
The correct binary representation of $0.145$ is $0.00100101000111...$
Normalized: $1.00101000111...$
The 8 bit mantissa is $00101000 = 0\mbox{x}28$
|
null |
I am confused about how **PP** and **BPP** are defined. Let us assume $\chi$ is the characteristic function for a language $\mathcal{L}$. *M* be the probabilistic Turing Machine. Are the following definitions correct:
$BPP =\{\mathcal{L} :Pr[\chi(x) \ne M(x)] \geq \frac{1}{2} + \epsilon \quad \forall x \in \mathcal... |
Concrete understanding of difference between PP and BPP definitions |
|complexity-theory|randomized-algorithms|complexity-classes| |
How to represent $0.148 * 2^{14}$ in normalized floating point arithmetic with the format
1 - Sign bit
7 - Exponent in Excess-64 form
8 - Mantissa
$(0.148)_{10} = (0.00100101\;111...)_2$
We shift it 3 bits to left to make it normalized $(1.00101\;111)_2 * 2^{11}$.
Exponent = $11+64 = (75)_{10... |
That looks correct to me. The difference between BPP and PP is that for BPP the probability has to be greater than $1/2$ *by a constant*, whereas for PP it could be $1/2+ 1/2^n$. So for BPP problems you can do probability amplification with a small number of repetitions, whereas for general PP problems you can't. |
I am trying to create an [isochrone](http://en.wikipedia.org/wiki/Isochrone_map) based on the OpenStreetMap data set. Everything works fine, I extracted data, processed it into a DAG, ran a Dijkstra algorithm over it. The result is a subset of the complete graph. This is an impression of the covered parts of the subset... |
Echoing @AJed advice, I recommend to turn your statement
I want to learn category theory so I can become better at Haskell.
on its head: learn Haskell, building on your programming intuition. Once you are an FP guru, it might be easier to pick up category theory (if you still care).
Category theory is sim... |
Consider the following problem:
>Let a *$k$-wheel* be defined as an indexed circularly linked list of $k$ integers. For example…
>>{3, 4, 9, -1, 6}
>…is a 5-wheel with 3 at position 0, 4 at position 1, and so on. A wheel supports the operation of rotation, so that a one-step rotation would turn the above whe... |
Using your notation:
$BPP =\{L : \exists $ a polynomial time Turing Machine $ M, $ and a costant $ 0 < c \leq 1/2$ such that $\forall x \; Pr[\chi_L(x) = M(x)] \geq \frac{1}{2} + c\}$
$PP =\{L : \exists $ a polynomial time Turing Machine $ M$ such that $\forall x \; Pr[\chi_L(x) = M(x)] > \frac{1}{2}\}$
The di... |
Using your notation:
$BPP =\{L : \exists $ a probabilistic polynomial-time Turing Machine $ M, $ and a costant $ 0 < c \leq 1/2$ such that $\forall x \; Pr[\chi_L(x) = M(x)] \geq \frac{1}{2} + c\}$
$PP =\{L : \exists $ a probabilistic polynomial-time Turing Machine $ M$ such that $\forall x \; Pr[\chi_L(x) = M(x)... |
I've designed an algorithm to find the longest common subsequence. these are steps:
Starts with `i = 0`
1. Picks the first letter from the first string start from ith letter.
2. Go to the second string looking for that picked letter.
3. If not found return to the first string and picks the next letter and ... |
Finding the longest common subsequence algorithm using hash table Slow |
|algorithms|subsequences| |
My favourite example of a context-sensitive language (CSL) is [SAT][1]. The [Landweber-Kuroda Theorem][2] says that CSL = [NSPACE][3]$[n]$. Any SAT instance has a linear-size certificate, so SAT is a CSL. See my question _[Context-sensitive grammar for SAT?][4]_ for references and discussion.
Many other NP-hard l... |
One optimization is to replace the access to <code>reached_index[item]</code> by a local variable which is initialized from the hash table at the beginning of the <code>for item</code> loop, and stored back to the hash table at the end of the loop.
Another optimization which will speed up things is to replace the ha... |
For most of this answer, I discuss the decision version of the problem, in which an instance having at most one solution is given (the "promise"), and you have to decide whether it has any solutions or none.
You can reduce PARTITION to your problem (exercise). (PARTITION is the problem of determining whether a set o... |
How is an algorithm with complexity $O(n log n)$ also in $O(n^2)$? I'm not sure exactly what its saying here, I feel it may be something to do with the fact that big-oh is saying less than or equal to, but I am not fully sure. Any have any ideas? Thanks. |
How is this algorithm in these two complexities? |
|algorithms|landau-notation| |
How is an algorithm with complexity $O(n \log n)$ also in $O(n^2)$? I'm not sure exactly what its saying here, I feel it may be something to do with the fact that big-oh is saying less than or equal to, but I am not fully sure. Any have any ideas? Thanks. |
The $O(\cdot)$ notation only gives an upper bound on the complexity. An algorithm has running time $O(n^2)$ if its running time can be bounded by $cn^2$ for some $c$. If it has running time $n$, say, then it's certainly bounded by $cn^2$ and so $O(n^2)$, though that's not the optimal bound.
A complement to $O(\cdot)... |
null |
You can try to use pushdown automata. Given a pushdown automaton for the original language, we construct one for the cyclic shift. The new automaton operates in two stages, corresponding to the $y$ and the $x$ part of the word $yx$ (where $xy$ is in the original language). In the first stage, whenever the automaton wou... |
null |
Let $A$ be the language $\{\langle M\rangle\mid M\text{ is a Turing machine that accepts only one string}\}$
According to my understanding, if a Turing machine is able to decide if another Turing machine will accept only one string, then the halting problem could also be solved. Therefore, $A$ is non-recursively enu... |
Language comprising of Turing machine encodings |
|turing-machines| |
IF a language is defined such that
L = (0+1)* if P = NP
$\phi$ otherwise
Then the language L is a regular language if P=NP, otherwise it is the empty langauge.
If P=NP, L is thus a recursive language(being regular)
But is L if P $\neq$ NP ? |
Recusively Enumerable or Recursive dependent on whether P=NP |
|complexity-classes| |
Let L1 and L2 be two languages defined as follows :
$L_1$ = { M|L(M) $\neq$ $\phi$ }
$L_2$ = { M|L(M) = $\phi$ }
where M denotes the encoding of a Turing Machine M.
L1 is the set of all TM encodings such that that TM does accept some language atleast, and L2 is the set of all TM encodings that do n... |
Deciding Recursive/Recursively Enumerable when given Turning machine encoding as a language |
|untagged| |
Only in one direction. As $\mathsf{P}=\text{co-}\mathsf{P}$, if $\mathsf{NP}\neq\text{co-}\mathsf{NP}$ then we would know that $\mathsf{P}\neq\mathsf{NP}$. However the reverse implication doesn't hold. If $\mathsf{P}\neq\mathsf{NP}$ then it's possible that either $\mathsf{NP}\neq\text{co-}\mathsf{NP}$ or $\mathsf{NP}=\... |
Does the proof of the widely believed result P $\neq$ NP depend on the proof of NP $\neq$ Co-NP ? |
If NP $\neq$ Co-NP then is P $\neq$ NP |
|complexity-classes|p-vs-np| |
Let $L_{1}$ and $L_{2}$ be two languages defined as follows :
$L_1 = \{ \langle M\rangle \mid L(M) \neq \emptyset \}$
$L_2 = \{ \langle M\rangle \mid L(M) = \emptyset \}$
where $\langle M\rangle$ denotes the encoding of a Turing Machine $M$.
$L_{1}$ is the set of encodings of TMs that accept at lea... |
As you note, both languages are undecidable, so neither are recursive. Then the remaining possiblities are recursively enumerable or not.
Note that $L_{1} = \overline{L_{2}}$, so if they were both recursively enumerable, then they would both be recursive, so we know at least one is not even recursively enumerable.
... |
|computability|undecidability| |
If a language is defined such that
$L = (0+1)^{\ast}$ if $\mathsf{P} = \mathsf{NP}$ and $\emptyset$ otherwise
Then $L$ is a regular language if $\mathsf{P} = \mathsf{NP}$, otherwise it is the empty langauge.
Therefore $\mathsf{P} = \mathsf{NP}$ , $L$ is recursive (being regular), but is $L$ still recursive... |
|computability|undecidability| |
|computability|turing-machines| |
As the question suggests, it is not too hard to show a reduction $HP \le L$, so $L\notin R$ (also, it is not in co$RE$). But, is it in $RE$ or not?
Lets show that $\overline{HP} \le L$ and conclude that $L\notin RE$.
The reduction goes like that: on input $(\langle M\rangle,x)$ we generate the TM $M_x$ that, on... |
|computability|reductions|undecidability| |
|computability|regular-languages|p-vs-np| |
As the question suggests, it is not too hard to show a reduction from the [halting problem (HP)](http://en.wikipedia.org/wiki/Halting_problem) to the language $A$ stated in the question, $HP \le A$.
This means that $A$ is undecidable, $A\notin R$ (also, it is not in co$RE$). But, is it in $RE$ or not?
Lets show th... |
Suppose $f$ is a fixpoint of $A$. First,
$$
f(0) = f(1) = f(2) = f(3) = 3f(3),
$$
and so $f(0) = f(1) = f(2) = f(3) = 0$. Second,
$$
f(5) = 5f(4) = 5f(5),
$$
and so $f(4) = f(5) = 0$. Third, if $n = 4m+3 \geq 7$ then $$f(n) = n f(2m+3),$$ while if $n = 4m+1 \geq 9$ then $$f(n) = n f(2m+2) = nf(2m+3).$$ In both ... |
I thought up a reduction on the train home, but Ran G. has beaten me to the punch ;). Nonetheless, as an exercise:
Let $E_{TM} = \{\langle M\rangle\mid L(M) = \emptyset\}$ (as usual). This language in not recursively enumerable (in fact you have asked [another question][1] where this is demonstrated.
We can show ... |
null |
In the comparison-based model of computation, you may implement the priority queue using a Fibonacci heap instead of an ordinary heap. This will give you the following bounds: $\mathcal{O}(1)$ amortized time for insert and $\mathcal{O}(\log n)$ amortized time for deletion operations.
If you depart from the comparis... |
null |
The language $L = \emptyset$ is indeed a recursive set. |
I have a set of strings. My goal is to find a minimal set of longest prefixes which will match most of that set.
For instance, if and my set is:
abracadabra
abracado
abramu
banana
bananasplit
bananaicecream
xylophone
zebra
zeitgeist
zello
I would want the outpu... |
Algorithm for determining minimal set of covering prefixes |
|algorithms|trees|data-compression|sets|coding-theory| |
I have a set of strings. My goal is to find a minimal set of longest prefixes which will match most of that set.
For instance, if and my set is:
abracadabra
abracado
abramu
banana
bananasplit
bananaicecream
xylophone
zebra
zeitgeist
zello
I would want the outpu... |
null |
Simply said, tail recursion is a recursion where the compiler could replace the recursive call with a "goto" command, so the compiled version will not have to increase the stack depth.
Sometimes designing a tail-recursive function requires you need to create a helper function with additional parameters.
For examp... |
Build a [trie][1]. Then find what you want.
[1]: http://en.wikipedia.org/wiki/Trie |
I have a set of strings. My goal is to find a minimal set of longest prefixes which will match most of that set.
For instance, if my set is:
abracadabra
abracado
abramu
banana
bananasplit
bananaicecream
xylophone
zebra
zeitgeist
zello
I would want the output to... |
null |
null |
Suppose I have the set of weights $W = \{w_1,w_2,\ldots,w_{50}\}$ where each $1 \le w_i \le 60$ is an integer. I am interested in determining **all** subsets (not just one, and not just the number of them) of $W$ with a fixed sum $s$. I realize this is obviously NP-hard, but are there some efficient ways (e.g. dynami... |
Subset-Sum for integers with bounded weights |
|dynamic-programming|np-hard| |
Yes, there is.
Have a look at: http://en.wikipedia.org/wiki/Subset_sum_problem#Pseudo-polynomial_time_dynamic_programming_solution |
Consider we have a $k$D array filled with $0$ and $1$'s. The number of elements in the array is $N$. We want to query a $k$D box and return
1. If there exist a $1$ in the box in $O(1)$ time.
2. Position of a $1$ in the box if there is one in $O(1)$ time.
We want to use as little space (in bit complexity) as po... |
Bit complexity of O(1) time range query in a $k$D array |
|reference-request|data-structures| |
Accepted language: $L(M)=\{0^{n}1^{n+1}: n\ge1$}
$$Q=\{q_0,q_1,q_2,q_3,q_4\} ,Σ = \{0,1\}, Γ =\{0,1,X,Y,B\}, F=\{q_4\}$$
So far I've succeeded to create a table for languages $\{0^n1^n\}$(without the red entry) and $\{0^n1^k:k\ge n\}$.
!["P" means the right side][1]
[1]: https://i.stack.imgur.com/NNJCd... |
Design the transition function |
|regular-languages|turing-machines| |
If you have managed to solve $0^n1^n$ then $q_4$ should simply proceed to the rightmost bit you haven't processed yet and verify that it's a 1 and that there is nothing following it. |
When doing mental calculus one can do:
- Given an integer k, sum all the digits (in base 10),
and if the result is a multiple of 3, then k is a multiple of 3.
Do you know of any algorithm working similarily but operating on binary numbers digits (bits)?
- At first, I was thinking of using the ready made... |
Algorithms computing if a number is a multiple of 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.