instruction
stringlengths
0
29.8k
⌀
Unfortunately, I've found out that this scheme is untenable _regardless_. The point of a log-represented input is to handle high dynamic range - but consider the following input: $$ [2^{-(2^{1000})}, 0, 2^{(2^{1000})}, 0] $$ An exact DFT would produce the following output: $$ [2^{-(2^{1000})} + 2^{(2^{1000}...
What would be an example of an algorithm that's in O(f(n)), but not in Θ(f(n))? The only thing I could think of, is an algorithm that behaves differently for different problem sizes, such as an algorithm that performs n operations for even problem sizes and n^2 operations for odd problem sizes. Such algorithms are r...
Example of an algorithm that's in O(f(n)), but not in Θ(f(n))
|time-complexity|
null
Finding the maximum value in an array of length $n$ is in $\mathcal{O}(n^2)$, but not in $\Theta(n^2)$. It is however in $\Theta(n)$. The reason is that $\mathcal{O}$ only gives an upper bound. Since finding the maximum value can be done in linear time, the complexity is in $\mathcal{O}(f(n))$ for any $f$ that grow...
Take any textbook algorithm, and let $g(n)$ be its worst case running time on inputs of size $n$. Define $f(n) = n \cdot g(n)$. Since $g(n) \le f(n)$ the algorithm runs in time $g(n) = O(f(n))$. Moreover, the algorithm does not run in time $\Theta(f(n))$ because it is false that $g(n)= \Omega(f(n))$, as it can b...
What would be an example of an algorithm that's in O(f(n)), but not in Θ(f(n))? The only thing I could think of, is an algorithm that behaves differently for different problem sizes, such as an algorithm that performs n operations for even problem sizes and n^2 operations for odd problem sizes. Such algorithms are r...
I have the following problem. Imagine a fully connected undirected graph, and I wish to calculate the optimal route for a traveller across that graph. Each vertice can only be visited once or not at all. Each vertex visited gives a positive payoff. However, each edge has a negative cost associated with its distance. Th...
Is there a well known name for an optimal route problem with continuous vertex weight?
|routing|
null
From Leslie Lamport *Time, Clocks, and the Ordering of Events in a Distributed System*: > The space-time diagram of Figure 1 might then yield the picture in Figure 2. Condition C 1 means that there must be a tick line between any two events on a process line, and condition C2 means that every message line must cross ...
null
First replace every terminal $a$ with a non-terminal $X_a$ and add a production $X_a \to a$. This because context sensitive grammars only work on non-terminals. Then, for every production $A_1\dots A_n \to B_1\dots B_n$ create a new non-terminal $D$ and replace the production with a sequence of productions $$\begin...
null
First replace every terminal $a$ with a non-terminal $X_a$ and add a production $X_a \to a$, because context sensitive grammars only work on non-terminals. Then, for every production $A_1\dots A_n \to B_1\dots B_n$ create a new non-terminal $D$ and replace the production with a sequence of productions $$\begin{alig...
This is a space-time diagram so, going from top to bottom, the time elapsed is increasing. <br> Here, A and B are two nodes that are broadcasting messages to the other nodes present with it on the same channel.<br> At t<sub>A</sub>, A senses that the channel is idle and then starts transmitting its message as shown in ...
So I've been trying to understand endianess for the past couple of days but I'm not sure if I'm overthinking this or not and I don't have anyone I can ask to confirm things. Here is how I look at things.. Say you have a defined value which represents the amount of pebbles there are in my city. Decimal: `‭119304...
Is this how endianess work relative to memory?
|computer-architecture|memory-access|
null
*Given $m$ sorted arrays $A_1,A_2,\dots,A_m$, also $\mid A_i\mid=n$ for each $i=1,2,\dots,m$. How we can compute $k^{th}$ smallest number in union of $A_i$s (i.e. $\cup_{i=1}^nA_i$) in at most $O(m\log mn)$?* $I.$ If I use Minheap to find $k^t{th}$ element, th running time will be $O(m+k\log mn)$, so that $k$ can be...
null
null
Well, you could use convolutions to filter the crossings, the horizontal and the vertical lines separately. With these, you could choose the connectivity of which ones to preserve (without jumps). Let's say you want to preserve the vertical lines. What you would need to do then is just erase the expanded crossings f...
I have a set of sets, for example ``` { {1, 2, 3}, {1, 2}, {2}, {2, 4} } ``` I want to find all sets which are not subsets of another set. For example, `{2}` and `{1, 2}` are both subsets of `{1, 2, 3}`, so my answer would just be `{1, 2, 3}` and `{2, 4}`. Let's call these "max sets". There is a clea...
Finding all sets which are not subsets of other sets
|algorithms|sets|finite-sets|
I have a set of sets, for example ``` { {1, 2, 3}, {1, 2}, {2}, {2, 4} } ``` I want to find all sets which are not subsets of another set. For example, `{2}` and `{1, 2}` are both subsets of `{1, 2, 3}`, so my answer would just be `{1, 2, 3}` and `{2, 4}`. Let's call these "max sets". There is a clea...
A morphological closing with an horizontal structuring element of sufficient width will erase the vertical segments. [![enter image description here][1]][1] The you can erode them to make them thicker and erase them in white to obtain non-touching vertical segments. [![enter image description here][2]][2] [...
First, there is a problem with the formulation of your question, which needs to be corrected before it can be answered. Algorithms are not in $O(f(n))$ or $\Theta(f(n))$. Functions can be. So, now we need to ask what function you are associating with an algorithm. Normally, when we use big-O notation in algorithm...
This is the Steiner tree problem in graphs with three terminals. It can be solved in polynomial time. You can use for example the Dreyfus-Wagner algorithm to solve it. In the case of three terminals it boils down to the following: Compute for each vertex (including the three terminals) to each of the terminals and cho...
This problem is still NP-hard. You can reduce the (NP-hard) unweighted, undirected Steiner tree problem to the directed one by replacing each edge by two anti-parallel arcs. You can reduce any unweighted directed Steiner tree problem to the problem that you describe by adding for each terminal t other than the root a t...
Your problem is NP-hard. The [Hamiltonian path problem](https://en.wikipedia.org/wiki/Hamiltonian_path_problem) is a special case of this problem: put +1 payoff on each vertex, 0 payoff on each edge, then there is a path that achieves total payoff $|V|$ iff there is a Hamiltonian path in the problem. Your problem i...
Echo state networks are theoretically equivalent to DFAs/NFAs, but how would you use an ESN to parse a regular language? Would you just feed many different input strings, some from the language and some not, and then train it to output one or zero to indicate whether the string belongs to the language?
Equivalence of echo state networks and DFAs/NFAs
|complexity-theory|finite-automata|neural-networks|
Depending upon your goals, learning from example inputs might not be the best approach. It might work fine in many cases, but there are some hard languages where it will fail. In particular, it is known that learning a regular language from a finite set of examples is NP-hard. See, e.g., https://cstheory.blogoverf...
null
I need to write recursive function in pseudocode for n-th string term of $a_n=n!+2^n$. Whole code should be contained in one function with $n$ as function argument.
How to write recursive function in pseudocode for this string $a_n=n!+2^n$
|pseudocode|
I need to write **recursive function** in pseudocode for n-th string term of $a_n=n!+2^n$. Whole code should be contained in one function with $n$ as function argument.
null
null
$$a_{n} = n! + 2^{n}\\a_{n+1} = (n+1)! + 2^{n+1}\\a_{n+1}-a_{n}=(n+1)!+2^{n+1}-n!-2^{n}= (n+1)\cdot n!-n! + 2\cdot2^{n}-2^{n}=n\cdot n!+2^n$$ $$a_{n+1} = n\cdot n! + 2^n + a_{n}$$ Implementing/writing a pseudocode should be fairly straightforward, although there are more terms which can be calculated recursively....
null
I need to write **recursive function** in pseudocode for n-th number term of $a_n=n!+2^n$. Whole code should be contained in one function with $n$ as function argument.
How to write recursive function in pseudocode for this number $a_n=n!+2^n$
null
Try to find functions $x=x(n)$ and $y=y(n)$ such that $a_{n+1} = x\cdot a_n + y\cdot a_{n-1}$. Thus $(n+1)! + 2^{n+1} = x n! + x 2^n + y (n-1)! + y 2^{n-1}$. Then hoping for good luck, try to separate the factorial and 2-power parts. $(n+1)! = x n! + y (n-1)! $ and $2^{n+1} = x 2^n + y 2^{n-1}$...
|recurrence-relation|pseudocode|
While the $\mathrm{NP}$-problems we typically study tend come with a natural notion of what a certificate is, for questions like this we need to be careful. Let's recall the certificate-based definition of $\mathrm{NP}$: A language $L$ is $\mathrm{NP}$, if there is a polynomial-time decidable language $R$ and a cons...
I don't think that we can find a simple recurrence of the form $$a_n=f(n,a_{n-1}).$$ Following Jan's method for a recurrence on the previous two terms, we write $$a_n=u(n)\,a_{n-1}+v(n)\,a_{n-2}$$ or $$n(n-1)(n-2)!+4\,2^{n-2}=u(n)((n-1)(n-2)!+2\,2^{n-2})+v(n)((n-2)!+2^{n-2}).$$ The by simple identificatio...
I don't think that we can find a simple recurrence of the form $$a_n=f(n,a_{n-1}).$$ Following Jan's method for a recurrence on the previous two terms, we write $$a_n=u(n)\,a_{n-1}+v(n)\,a_{n-2}$$ or $$n(n-1)(n-2)!+4\,2^{n-2}=u(n)((n-1)(n-2)!+2\,2^{n-2})+v(n)((n-2)!+2^{n-2}).$$ The by simple identificatio...
I don't think that we can find a simple recurrence of the form $$a_n=f(n,a_{n-1}).$$ Following Jan's method for a recurrence on the previous two terms, we write $$a_n=u(n)\,a_{n-1}+v(n)\,a_{n-2}$$ or $$n(n-1)(n-2)!+4\,2^{n-2}=u(n)((n-1)(n-2)!+2\,2^{n-2})+v(n)((n-2)!+2^{n-2}).$$ Then by simple identificati...
I am having troubles in understanding why this proof is done like that. Why do we need to make a reduction to Ld which isn't even in RE to disprove Lu being rec? And why does the book (Automata Theory, Languages and computation by Hopcroft, Motwani, ullman) constructs a machine for Ld to get a contradiction? [T...
Reduction to Diagonalization language to prove that Universal language is not REC
|formal-languages|automata|
The reduction is not done **to** the diagonalization language, but **from** the diagonalization language. The difference is very important here. The idea of reduction is that the fact that there is a reduction from $A$ to $B$, noted $A\leqslant B$, can be translated as: > if we know how to solve $B$, then we know...
Let's say we have a NFA such as follows: [![enter image description here][1]][1] We know it's equivalent DFA is follows, after minimization: [![enter image description here][2]][2] We know that when converting from NFA to DFA, the resultant DFA would have around 2^( number of states in NFA ). This is where I ge...
When converting from nfa to dfa, do we always ignore the trap state?
|automata|finite-automata|nondeterminism|
You can indeed ignore dead states in NFA when doing the conversion. Actually, even without considering the conversion, it is generally common not to draw dead states in NFA (the notion of complete automaton stands for DFA, not for NFA).
This is the Steiner tree problem in graphs with three terminals. It can be solved in polynomial time. You can use for example the Dreyfus-Wagner algorithm to solve it. In the case of three terminals it boils down to the following: Compute for each vertex (including the three terminals) the shortest path to each of the...
null
null
I am reading Michael Sipser's "Theory of Computation" 2nd edition, chapter 1 , Topic "Non determinism" ( Section 1.2 ) Let's use this E-NFA as an example [![enter image description here][1]][1] My question is, do we transition along "epsilon transition" before reading any input or after reading any input. a...
Confusion regarding the intuition behind epsilon transition in NFA
|automata|finite-automata|computation-models|nondeterminism|
In the case of the E-NFA shown in the first diagram, the epsilon transitions are taken before reading any input. This is because epsilon transitions do not consume any input and are taken automatically when the machine is in a state that has an epsilon transition. Therefore, in the example you provided, the correct ...
*Given $m$ sorted arrays $A_1,A_2,\dots,A_m$, also $\mid A_i\mid=n$ for each $i=1,2,\dots,m$. How we can compute $k^{th}$ smallest number in union of $A_i$s (i.e. $\cup_{i=1}^nA_i$) in at most $O(m\log mn)$?* $I.$ If I use Minheap to find $k^t{th}$ element, th running time will be $O(m+k\log mn)$, so that $k$ can be...
null
In the case of the E-NFA shown in the first diagram, the epsilon transitions are taken before reading any input. This is because epsilon transitions do not consume any input and are taken automatically when the machine is in a state that has an epsilon transition. Therefore, in the example you provided, the correct ...
So I've been trying to understand endianess for the past couple of days but I'm not sure if I'm overthinking this or not and I don't have anyone I can ask to confirm things. Here is how I look at things.. Say you have a defined value which represents the amount of pebbles there are in my city. Decimal: `‭119304...
|computer-architecture|cpu|memory-access|
Possibly related to [this][1]. Let $T$ be the text and $n$ be the length of the pattern. I understand that if substrings of $T$ are interpreted as base-$d$ numbers where $d$ is the alphabet's size, then for all suitable $k$: $$T[k+1\text{..}k+n] = (T[k\text{..}k+n−1] − T[k]⋅d^{n-1})⋅d + T[k+n]$$ What I don't understa...
Understanding Rabin-Karp's rolling hash computation
|search-algorithms|modular-arithmetic|rolling-hash|
Possibly related to [this][1]. Let $T$ be the text and $n$ be the length of the pattern. I understand that if substrings of $T$ are interpreted as base-$d$ numbers where $d$ is the alphabet's size, then for all suitable $k$: $$T[k+1\text{..}k+n] = (T[k\text{..}k+n−1] − T[k]⋅d^{n-1})⋅d + T[k+n]$$ What I don't understa...
null
Possibly related to [this][1]. Let $T$ be the text and $n$ be the length of the pattern. I understand that if substrings of $T$ are interpreted as base-$d$ numbers where $d$ is the alphabet's size, then for all suitable $k$: $$T[k+1\text{..}k+n] = (T[k\text{..}k+n−1] − T[k]\cdot d^{n-1})\cdot d + T[k+n]$$ What I don'...
There are **two** modulo operations for a modulus $0\not=q\in\Bbb N$. $\newcommand{\q}{\!\!\pmod q}$ - Let $\text{mod}_q:\Bbb Z\to\Bbb Z/q\Bbb Z$, $\text{mod}_q(x)=\{\cdots, x-2q,x-q, x, x+q, x+2q, \cdots,\}$. We also write the last set as $\bar x_q$ or $x\q$ or, with $q$ understood, $\bar x$ or even just $x$. - L...
null
I don't think it's a CFL, but I'm having a hard time using the pumping lemma to prove this. Is there any way I can use homomorphism? Maybe h(a)= a, h(b) = lambda... If the pumping lemma is more appropriate then maybe... let m = constant of pumping lemma for some string w = a^nb^k let w =xyz such that |xy|<=m and |...
Is a^n b^k , 0 <= n <= k^2, a context-free language?
|context-free|
|regular-languages|context-free|pumping-lemma|
For a project I'm working on, I need to generate some data to test the Gzip compressor, and I wrote [my own](https://github.com/dannyniu/NestedMarkovChain/) implementation of Markov chain for it, and it's a 2-level nested one. But when I generate data using my script and feed it to Gzip, it always - without exceptio...
Why is data generated from a randomly constructed Markov chain not compressible?
|data-compression|markov-chains|
I have no idea how to approach this question... How would I go about proving or disproving this? any explanation is appreciated.
Is a^n , n = 3j+4k , n>=0, a context-free language?
|regular-languages|context-free|pumping-lemma|
If we think of the algorithmic problem of doing a convolution of two arrays, it turns out that converting them to the frequency domain first and then doing a dot product is equivalent. And this leads to an efficient algorithm where we invoke the FFT to go to the frequency domain efficiently (in $O(n \log(n))$ time). ...
What algorithms apart from FFT get a computational boost by leveraging complex numbers?
|polynomials|fast-fourier-transform|
For a project I'm working on, I need to generate some data to test the Gzip compressor, and I wrote [my own](https://github.com/dannyniu/NestedMarkovChain/blob/eac79f5367fbade7060e082bfb7de611bece832b/src/NestedMarkovChain.py) implementation of Markov chain for it, and it's a 2-level nested one. But when I generate ...
In the factory function that generates MC definition, each state has the probability of transitioning to other states that're uniformly random, I guess that this is the biggest problem. Suggestion for improvement: Make the probability more sparse and skewed for each state for starters. (I'll make a commit soon)