instruction
stringlengths
0
29.8k
⌀
|algorithms|graphs|optimization|sets|
null
Because of the choices for $w_i$, it is easier to track the conditions if we include non-determinism. ------ Let $L_1$ be accepted by DFA $D_1=(Q, \{0,1\}, \delta_1, q_0, F)$. Let NFA $N=(Q\sqcup Q_\#\sqcup\{\text{dead}\}\}, \{0,1,\#\},\delta, q_0, F)$, where - $Q_\#$ is a $\#$-tagged copy of $Q$, i.e., $Q...
Because of the choices for $w_i$, it is easier to track the conditions if we include non-determinism. ------ Let $L_1$ be accepted by DFA $D_1=(Q, \{0,1\}, \delta_1, q_0, F)$. Let NFA $N=(Q\sqcup Q_\#\sqcup\{\text{dead}\}\}, \{0,1,\#\},\delta, (q_0)_\#, F)$, where - $Q_\#$ is a $\#$-tagged copy of $Q$, i.e...
Because of the choices for $w_i$, it is easier to track the conditions if we include non-determinism. ------ Let $L_1$ be accepted by DFA $D=(Q, \{0,1\}, \delta, q_0, F)$. Let NFA $N=(Q\sqcup Q_\#\sqcup\{\text{dead}\}\}, \{0,1,\#\},\tau, (q_0)_\#, F)$, where - $Q_\#$ is a $\#$-tagged copy of $Q$, i.e., $Q_...
null
Source: Hanoi student competition of unknown year (Kì thi học sinh giỏi thành phố) Additional conditions: N is a positive integer in range [1, 2^64 - 1] K is a positive integer in range [3, 10]
Find a number not larger than some integer N and is the product of K consecutive primes
|mathematical-programming|binary-search|primes|
I am preparing for my CS exam and found this question in a collection of old exams: > Find a DFA and NFA with Σ = {o,p,q} that checks if the substrings op and pq are present in the string. I thought, I understood this topic, but I can not find a regular expression for this problem. My initial thought was `{o ...
DFA and NFA with 2 Substrings
|regular-languages|finite-automata|regular-expressions|
Find an automaton for $L_1= \{uopv\mid u,v\in \Sigma^*\}$ and an automaton for $L_2 = \{upqv\mid u,v\in\Sigma^*\}$ (this should be easy enough). Then, you can compute the product automaton of the two languages, accepting $L_1\cap L_2$.
Find the largest possible number not larger than some integer N and is the product of K consecutive primes
Source: Hanoi student competition of unknown year (Kì thi học sinh giỏi thành phố) Additional conditions: N is a positive integer in range [1, 2^64 - 1] K is a positive integer in range [3, 10] Example: N = 106, K = 3 => res = 105 (3 * 5 * 7)
I am looking at a specific variant of subgraph isomorphism: - **Instance** A graph $G = (V_G, E_G)$ and a target graph $H = (V_H, E_H)$ such that **$|V_G| = |V_H|$**. - **Question** Is there a subgraph $G' = (V'_G, E'_G)$ of $G$ that is isomorphic to $H$? (Note the condition $|V_G| = |V_H|$ above, which implie...
Subgraph Isomorphism with Same Number of Nodes
|complexity-theory|graphs|parameterized-complexity|graph-isomorphism|
I am looking at a specific variant of subgraph isomorphism: - **Instance** A graph $G = (V_G, E_G)$ and a target graph $H = (V_H, E_H)$ such that **$|V_G| = |V_H|$**. - **Question** Is there a subgraph $G' = (V'_G, E'_G)$ of $G$ that is isomorphic to $H$? (Note the condition $|V_G| = |V_H|$ above, which implie...
Subgraph Isomorphism with Same Number of Nodes -- Homomorphism
I am looking at a specific variant of subgraph isomorphism: - **Instance** A graph $G = (V_G, E_G)$ and a target graph $H = (V_H, E_H)$ such that **$|V_G| = |V_H|$**. - **Question** Is there a subgraph $G' = (V'_G, E'_G)$ of $G$ that is isomorphic to $H$? (Note the condition $|V_G| = |V_H|$ above, which implie...
I am looking at a specific variant of subgraph isomorphism: - **Instance** A graph $G = (V_G, E_G)$ and a target graph $H = (V_H, E_H)$ such that **$|V_G| = |V_H|$**. - **Question** Is there a subgraph $G' = (V'_G, E'_G)$ of $G$ that is isomorphic to $H$? (Note the condition $|V_G| = |V_H|$ above, which implie...
Let us do some rough estimate. Since the ratio between two consecutive primes <!-- that are not too small--> is about $1$, if the product of $K$ consecutive primes is almost equal to $N$, then each of them is about $N^{1/K}$. Since $N\lt 2^{64}$ and $K\ge3$, $N^{1/K}\lt2^{64/3}\approx 2641636$. Using standard techniqu...
This naïve sampling algorithm I am talking about is fairly simple: create a set for storing chosen items first, randomly select an item from the array, and examminate if it is in the set. If it isn't, add it to the set, otherwise we will skip and reselect. This process will be repeated until required amount of samples ...
Naïve array sampling algorithm: the possibility of a item being chosen and its time complexity?
|algorithms|randomness|statistics|sampling|
Let us do some rough estimate. Since the ratio between two consecutive primes <!-- that are not too small--> is about $1$, if the product of $K$ consecutive primes is almost equal to $N$, then each of them is about $N^{1/K}$. Since $N\lt 2^{64}$ and $K\ge3$, $N^{1/K}\lt2^{64/3}\approx 2641636$. Using standard techniqu...
|algorithms|time-complexity|mathematical-programming|binary-search|primes|
Naïve array sampling algorithm: the possibility of a item being chosen and its time complexity
This naïve sampling algorithm I am talking about is fairly simple: create a set for storing chosen items first, randomly select an item from the array, and examminate if it is in the set. If it isn't, add it to the set, otherwise we will skip and reselect. This process will be repeated until required amount of samples ...
I want to show that the language $$ \left\{ \left\langle M\right\rangle \mid\substack{\text{M is a TM and there exists a poly TM $M'$ such that}\\ \text{if M halts on input $w$, $M'$ halts on $w$ and answers the same} } \right\} $$ is not decideable, using Rice's theorem. I have a hard time understanding why t...
Showing that a property is semantic - Rice's theorem
|turing-machines|computability|undecidability|rice-theorem|
Assume that $m$ items have already been chosen. The next one needs to be different, which occurs with probability $1-\dfrac mn$. So the expectation of the number of drawings is $\dfrac{n}{n-m}$. To reach the quorum of $k$ numbers, you will need $$\sum_{m=0}^{k-1}\frac n{n-m}=n\left(H_{n}-H_{n-k+2}\right)\sim n\log\f...
It can be checked easily whether the product of the first $K$ primes is larger than $N$. If yes, there is no such number that is not larger than $N$ and is the product of $K$ consecutive primes. Otherwise, list consecutive primes nears $N^{1/K}$ as $p_1, p_2,\cdots,p_K,p_{K+1}, \cdots, p_{2K-1}$ in increasing order...
Assume that $m$ items have already been chosen. The next one needs to be different, which occurs with probability $1-\dfrac mn$. So the expectation of the number of drawings is $\dfrac{n}{n-m}$ (geometric law). To reach the quorum of $k$ numbers, you will need $$\sum_{m=0}^{k-1}\frac n{n-m}=n\left(H_{n}-H_{n-k}\righ...
Assume that $m$ items have already been chosen. The next one needs to be different, which occurs with probability $1-\dfrac mn$. So the expectation of the number of drawings is $\dfrac{n}{n-m}$ (geometric law). To reach the quorum of $k$ numbers, you will need $$\sum_{m=0}^{k-1}\frac n{n-m}=n\left(H_{n}-H_{n-k}\righ...
I want to show that the language $$L= \left\{ \left\langle M\right\rangle \mid\substack{\text{M is a TM and there exists a poly TM $M'$ such that}\\ \text{if M halts on input $w$, $M'$ halts on $w$ and answers the same} } \right\} $$ is not decideable, using Rice's theorem. I have a hard time understanding why...
Assuming you really need the number for all pairs of sets and hearing that we are thinking of users in communities you could use the following algorithm which relies on the idea that the the average number of sets/communities a user is part of $k$ is much smaller that the number of total sets $k << n$. Let $m$ refer t...
I want to create a table that has the following results: id | field1 | field2 1 | 1 | 1 2 | 2 | 2 3 | 3 | 3 4 | 4 | 4 5 | 1 | 2 6 | 2 | 3 7 | 3 | 4 8 | 4 | 1 9 | 1 | 3 10 | 2 ...
how can I fix my SQL for loop so that the index is not out of bounce?
|algorithms|loops|
If the order of the values is not important, you could simply do: id = 1 for i = 1 to 4 do for j = 1 to 4 do INSERT(id, i, j) id += 1 If you want the exact same order as stated in your question, I think this is a solution: id = 1 for i = 1 to 4 do f...
null
Given n points in a 2d plane I.E $ (x_1,y_1),(x_2,y_2)\dots (x_n,y_n) $. Create a data structure that holds the points and a method closer$(a,b)$ that returns all the points in the data structure that are closer to $(0,0) $ than to $(a,b) $. The preprocessing and creation of the data structure have no complexity ...
n points in 2d plane and a method(a,b) that returns all points closer to 0 than (a,b)
|data-structures|
I've come across this problem when working on a personal project of mine. I need an efficient algorithm of counting the number of overlaps between all pair combinations of n sets. Example: Set a = [adam, ben, charlie, ...] Set b = [adam, john, kenny, ...] Set c = [adam, john, eve, ...] ... Set n T...
This is equivalent to finding all the points in a query half-plane, which has a cute, non-obvious solution in terms of [convex layers](https://en.wikipedia.org/wiki/Convex_layers), using [fractional cascading](https://en.wikipedia.org/wiki/Fractional_cascading) to speed up moving from layer to layer.
Yes, another way is to think about the In-order Traversal. You go Left-Root-Right. Well a property of BST is the left node is less than Root and right node is greater than Root. By going in the specified order, you start with the left most sub tree, and work your way over to the right most subtree. This will result in ...
**Question**: Suppose $a, b$ are sequences with $n=|a|,m=|b|$ lengths, and $ed(a,b)$ denotes [edit distance][1] between them. what is the complexity of computing $ed(a[i:j],b)$ for all values $1\le i<j\le n$? The following dynamic programing solution has $O(n m)$ time complexity: Let $M$ denote the DP table with...
Finding all edit distance of all substrings
|edit-distance|
null
There is a mapping from each possible list $P$ to an interval $[\ell,r)$ contained in $[0,1)$, such that the resulting intervals (if you consider all possible lists) form a partition of $[0,1)$. In particular, if $P=(p_1,\dots,p_N)$ and $N\ge 1$, define $$f(P) = w_{p_N} f(p_1,\dots,p_{N-1}) + w_1 + w_2 + \dots + ...
null
null
**Question**: Suppose $a, b$ are sequences with $n=|a|,m=|b|$ lengths, and $ed(a,b)$ denotes [edit distance][1] between them. what is the complexity of computing $ed(a[i:j],b)$ for all values $1\le i<j\le n$? **$O(n m)$ to compute $ed(a[1:i],b)$s** Let $A$ denote the DP table with $(n+1)\times (m+1)$ size. For all ...
Busy Beaver is an uncomputable function that grows quicker than any computable function. That means there exist functions f such that for all computable functions g: g in O(f). There is an upper bound on complexity of computable functions. The question is whether or not there is a **computable** function like that. ...
Is there a maximally complex computable function?
|complexity-theory|
Busy Beaver is an uncomputable function that grows quicker than any computable function. That means there exist functions f such that for all computable functions g: g in O(f). There is an upper bound on the order of computable functions. The question is whether or not there is a **computable** function like that. S...
Is there a maximal order of computable functions?
how can I fix my SQL for loop so that the index is not out of bounds?
Suppose that such a computable function $f$ exists. The function $h(n) = nf(n) + n$ is also computable, but $h(n)$ is not $O(f(n))$. We can similarly rule out a uniformly computable countable order, that is, a uniformly computable sequence of functions $f_i$ such that for each computable $g$, we have $g = O(f_i)$ fo...
Informally speaking, a property is *semantic* if it only depends on the final "outcome" of running $M$ on a given input rather than on the workings of $M$. In order to formalize this, with each Turing machine $M$, associate a partial function $\Lambda$ from inputs $\Sigma^*$ to pairs $\{0,1\} \times \Sigma^*$, where th...
Busy Beaver is an uncomputable function that grows quicker than any computable function. That means there exist functions f such that for all computable functions g: g in O(f). There is an upper bound on the order of computable functions. [Here][1] I asked whether there is a computable function bounding all computab...
Is there a minimal order of an uncomputable function that bounds all computable functions?
|complexity-theory|
I was told to built a PDA that recognizes the following language: L={x#y ∣ x, y ∈ {0,1}* ∧ x≠y} See, To approach this, we can have followiing Cases: **Case 1**: Let length of 'X' is more than length of 'Y',i.e., |x| > |y|, it should be accepted in our PDA. **Case 2**:...
I was told to built a PDA that recognizes the following language: L={x#y ∣ x, y ∈ {0,1}* ∧ x≠y} See, To approach this, we can have followiing Cases: **Case 1**: Let length of 'X' is more than length of 'Y',i.e., |x| > |y|, it ...
null
Suppose that $h$ is such that $g = O(h)$ for all computable $g$. Let $H(n) = h(n)/n$. I claim that $H$ also satisfies $g = O(H)$ for all computable $g$. Otherwise, let $g$ be a computable function such that $g$ is not $O(H)$. In particular, there are infinitely many $n$ such that $g(n) \geq H(n)$, and so $n g(n) \geq h...
null
null
I was reading in Wiki about NP-intermediate problems ([link][1]) and saw the IMSAT problem over there. There is no Wiki page for that problem and they only cite [this paper][2]. In the paper they deifine the MSAT problem as: > Recall that the satisfiability problem (SAT) is to decide whether a set of proposit...
MSAT and IMSAT problems (restricted versions of SAT)
|complexity-theory|satisfiability|
null
Are there monotonically increasing uncomputable functions f that are bounded by computable functions? $$ \exists f,g: f\ uncomputable\ \land f\ monotonically\ increasing\ \land\ g\ computable\ \land\ f \in O(g) $$
Do uncomputable functions exist that are of the order of a computable function?
|complexity-theory|
Yes. Let $L$ be any undecidable language (e.g. the halting problem), w.l.o.g. encoded over the alphabet $\{0, 1\}$ and such that all $x \in L$ start with $1$. Further, let $\leq_\text{lex}$ denote the lexicographical order of strings over the alphabet $\{0, 1\}$ and let $\operatorname{bin}(n)$ denote the binary represe...
null
For your first question, I'll give an elementary proof for the $\mathsf{NP}$-hardness of $\mathrm{MSAT}$ by reduction from $\mathrm{SAT}$. Let $\varphi$ be a propositional formula in CNF (i.e., a $\mathrm{SAT}$ instance) consisting of the clauses $C_1, ..., C_m$ and let $C_i^+$ and $C_i^-$ denote the set of positive...
null
null
null
Assume I have a language $L$ with well-defined semantics. Showing Turing-completeness is straightforward: if I write a program simulating the universal TM, I'm done. What I'm concerned about is another direction. How do we show that a program in $L$ can be simulated by TM when $L$ supports things like: * File I/O (I...
What exactly does Turing Equivalence mean?
|turing-completeness|
null
Assume I have a programming language $L$ with well-defined semantics. Showing Turing-completeness is straightforward: if I write a program using $L$ simulating the universal TM, I'm done. What I'm concerned about is another direction. How do we show that a program in $L$ can be simulated by TM when $L$ supports thing...
|programming-languages|turing-completeness|
It's just the ordinary meaning of the words extent and resolution, only applied to time instead of space. You can think of space-time as a kind of a continuous block, instead of just thinking of time as something that ticks away. E.g. if you imagine a graph where one axis is space, and another is time, then the spa...
It's just the ordinary meaning of the words extent and resolution, only applied to time instead of space. You can think of space-time as a kind of a continuous block, instead of just thinking of time as something that ticks away. E.g. if you imagine a graph where one axis is space, and another is time, then the spa...
null
null
null
Because of the rule "we move all these points to a visited set and continue", your problem is degenerate. Because the hull of a single point is the point itself, which you eliminate and continue from an empty set. (Also works with the first two or first three points, always forming a convex polygon.)