instruction
stringlengths
0
29.8k
⌀
I think this can be done using a bit of dynamic programming. First, let us try to solve a different problem, which is computing $|M|$ given $n$, $a$ and $b$. Denote $f(n, a, b)$ this number. Note that a string in $M$ is composed of a $1$, followed by a sequence of substrings of the form $0^k1$, with $k\in \{a, a+1, ...
null
I think this can be done using a bit of dynamic programming. First, let us try to solve a different problem, which is computing $|M|$ given $n$, $a$ and $b$. Denote $f(n, a, b)$ this number. Note that a string in $M$ is composed of a $1$, followed by a sequence of substrings of the form $0^k1$, with $k\in \{a, a+1, ...
null
This looks like it is at least as hard as the [induced subgraph isomorphism problem](https://en.wikipedia.org/wiki/Induced_subgraph_isomorphism_problem). Suppose that all $w$ vectors are 0. Then your question is identical to asking whether for a maximal induced subgraph of $G_1$ that is isomorphic to an induced subgr...
null
null
null
In this question, I'm going to introduce a prime factorization algorithm which I'm working on as my personal project. I may attach a Python code to introduce the algorithm. If it contravenes the rule please let me know, I will consider it editing as a pseudo-code or substitute it with some link. import timeit...
Finding the time complexity of a prime factorization algorithm
|algorithms|complexity-theory|time-complexity|integers|factoring|
I have just implemented a parser on the relational database. Parsing is done with recursive query. I built the tokenizer, manually cobbled together the state event transition and action table, and I have an action function which updates the stack for each thread of parallel parsing. All is working nicely. The o...
Simple description of the LR(0) table generator algorithm?
|finite-automata|formal-grammars|parsers|
null
In this question, I'm going to introduce a prime factorization algorithm which I'm working on as my personal project. I may attach a Python code to introduce the algorithm. If it contravenes the rule please let me know, I will consider it editing as a pseudo-code or substitute it with some link. import timeit...
In this question, I'm going to introduce a prime factorization algorithm which I'm working on as my personal project. I may attach a Python code to introduce the algorithm. If it contravenes the rule please let me know, I will consider it editing as a pseudo-code or substitute it with some link. import timeit...
In this question, I'm going to introduce a prime factorization algorithm which I'm working on as my personal project. I may attach a Python code to introduce the algorithm. If it contravenes the rule please let me know, I will consider it editing as a pseudo-code or substitute it with some link. import timeit...
In this question, I'm going to introduce a prime factorization algorithm which I'm working on as my personal project. I may attach a Python code to introduce the algorithm. If it contravenes the rule please let me know, I will consider it editing as a pseudo-code or substitute it with some link. import timeit...
It is known that the $\mathbf{P}\overset{?}{=}\mathbf{NP}$ problem is equivalent to asking whether there exists a polynomial-time Turing machine that decides an $\mathbf{NP}$-complete problem. Let's say this problem is subset-sum. Now I'm considering enumerating all the Turing machines with fewer than $s$ states. Since...
Practicability of enumerating all Turing machines with fewer than $s$ states to find a potential polynomial-time algorithm for subset-sum?
|turing-machines|np-complete|np|
In this question, I'm going to introduce a prime factorization algorithm which I'm working on as my personal project. I may attach a Python code to introduce the algorithm. If it contravenes the rule please let me know, I will consider it editing as a pseudo-code or substitute it with some link. import timeit...
There are [a lot](https://cs.stackexchange.com/questions/42534/how-many-turing-machines-are-there-with-c-characters-and-n-states) of Turing machines, so no, this idea is completely unpractical (I don't think there is really a loophole, since you are considering many restrictions). For example, there are roughly $10^{14...
Is there a number $\alpha < 1$ such that the independent set problem is polynomial for input graphs whose independence number is at least $\alpha n$ (where $n$ is the number of vertices)?
Independent set problem for graphs with very large independent sets
|complexity-theory|graphs|
In this question, I'm going to introduce a prime factorization algorithm which I'm working on as my personal project. I may attach a Python code to introduce the algorithm. If it contravenes the rule please let me know, I will consider it editing as a pseudo-code or substitute it with some link. import timeit...
In this question, I'm going to introduce a prime factorization algorithm which I'm working on as my personal project. I may attach a Python code to introduce the algorithm. If it contravenes the rule please let me know, I will consider it editing as a pseudo-code or substitute it with some link. import timeit...
In this question, I'm going to introduce a prime factorization algorithm which I'm working on as my personal project. I may attach a Python code to introduce the algorithm. If it contravenes the rule please let me know, I will consider it editing as a pseudo-code or substitute it with some link. import timeit...
_(Disclaimer: I'm not a computer scientist and have not read most of these books. I wish more people would address this interesting question.)_ There are various options out there. Many of them have titles in the lines of _"Introduction to Computer Science"_, _"Fundamentals of Computing"_, etc. For example, I enj...
There is no such $\alpha$ unless $\mathsf{P}= \mathsf{NP}$. Assuming such an $\alpha$ exists, you could solve the problem Independent Set for any graph in polynomial time. Indeed, suppose $G = (V, E)$ a graph and $n = |V|$ ($V = \{1, 2, …, n\}$). Consider $N = \left\lceil \frac{n}{1-\alpha}\right\rceil$, $K = N - n$...
# Problem Description Given $a, b, n \in \mathbb{N}$ with $a < b < n$. Let $M$ be the set of all possible bit strings of length $n$ which begin and end with one and have at least $a$ and at most $b$ zeros between every pair of successive ones: $$ AZ_s(x, y) :\equiv s_{x} = s_{x+1} = \ldots = s_{y} = 0 \\ M := ...
null
Here's a simple solution that runs in O(nk) time. The basic idea is to go through every possible value of x and use DP to calculate the longest increasing subsequence up to each a_i that conforms to the conditions. For each i, there are 3 states: 1. We haven't come across a value of a_i for which a_i != b_i and thus ...
I didn't read the details of how your code functions, so I won't comment on your algorithm. However, the code itself seems to have a time complexity of `O(sqrt(A))`. As A becomes very large, B approaches `sqrt(2A)`, making D approach `-sqrt(2A)`. Then, your second `while` loop seems to have a time complexity of `O(B)`,...
null
In this question, I'm going to introduce a prime factorization algorithm which I'm working on as my personal project. I may attach a Python code to introduce the algorithm. If it contravenes the rule please let me know, I will consider it editing as a pseudo-code or substitute it with some link. import timeit...
In this question, I'm going to introduce a prime factorization algorithm which I'm working on as my personal project. I may attach a Python code to introduce the algorithm. If it contravenes the rule please let me know, I will consider it editing as a pseudo-code or substitute it with some link. import timeit...
null
In this question, I'm going to introduce a prime factorization algorithm which I'm working on as my personal project. I may attach a Python code to introduce the algorithm. If it contravenes the rule please let me know, I will consider it editing as a pseudo-code or substitute it with some link. import timeit...
In this question, I'm going to introduce a prime factorization algorithm which I'm working on as my personal project. I may attach a Python code to introduce the algorithm. If it contravenes the rule please let me know, I will consider it editing as a pseudo-code or substitute it with some link. import timeit...
In this question, I'm going to introduce a prime factorization algorithm which I'm working on as my personal project. I may attach a Python code to introduce the algorithm. If it contravenes the rule please let me know, I will consider it editing as a pseudo-code or substitute it with some link. import timeit...
null
In this question, I'm going to introduce a prime factorization algorithm which I'm working on as my personal project. I may attach a Python code to introduce the algorithm. If it contravenes the rule please let me know, I will consider it editing as a pseudo-code or substitute it with some link. import timeit...
I have just implemented a parser on the relational database. Parsing is done with recursive query. Note: one commenter was misled by the word "recursive" before "query" to think "recusive descent". But no. I am not talking about recursive descent top-down, I am talking about bottom up, LR, simple, no look-ahead, driven...
null
null
null
Concatenation of two non-regular languages may be regular. Constructive Proof: Let $L$ be any non-regular language. Now, we know $L’$ is also non-regular. Consider $(L \cup \{ \epsilon \})$ ; $(L’ \cup \{ \epsilon \})$, both of which are non-regular. Now, $(L \cup \{ \epsilon \}).(L’ \cup \{ \epsilon \}) = ...
If one proves that the lower bounds of an $NP$ problem, are not bounded by any polynomial, is this enough to prove that $P$ does not equal $NP$?
does superpolynomial lower bounds of a problem in $NP$ mean that $P\neqNP$?
|complexity-theory|p-vs-np|
A sequence $(a_1,a_2, \dots, a_n) $ and natural numbers $n$ and $k$ are given. We want to calculate the longest increasing subsequence of sequence $(b_1,b_2, \dots, b_n)$ for which there exist an interval of pointers $[l, r]$ and a number $x$, $-k\le x\le k$, such that $b_i = a_i + x$ for $i \in [l, r]$, and $b_i = ...
We want to distribute 3*n known cards among 3 players evenly given a set of constraints that prohibits some players from having certain suits. For example: We want to distribute 1H, 2H, 3S, 4S, 5D, 6D (second letter refers to suit of card) among three players A, B, C such that A does not get any card of suit Heart...
Distributing cards randomly given constraints
|probability-theory|board-games|
We want to distribute 3*n known cards among 3 players evenly given a set of constraints that prohibits some players from having certain suits. For example: We want to distribute 1H, 2H, 3S, 4S, 5D, 6D (second letter refers to suit of card) among three players A, B, C such that A does not get any card of suit Heart...
null
does superpolynomial lower bounds of a problem in $NP$ mean that $P \neq NP$?
Yes, if you prove a super-polynomial lower bound on time needed to decide a problem $\Pi \in \mathsf{NP}$, then this means that $\Pi \not\in \mathsf{P}$. Since $\Pi \in \mathsf{NP} \setminus\mathsf{P}$, the set $\mathsf{NP} \setminus\mathsf{P}$ cannot be empty, i.e., $\mathsf{P} \subset \mathsf{NP}$.
Yes. Unfortunately _proving_ even a worse than linear lower bound is very often very difficult.
Does superpolynomial lower bounds of a problem in $NP$ mean that $P \neq NP$?
null
In this question, I'm going to introduce a prime factorization algorithm which I'm working on as my personal project. I may attach a Python code to introduce the algorithm. If it contravenes the rule please let me know, I will consider it editing as a pseudo-code or substitute it with some link. import timeit...
I'm trying to optimize a practical problem in a database query. Suppose we have a db table`Products` and each product has a few numeric properties. I save the properties values in a different table `ProductProperty` table because because the user can add more property types. The user wants to look for products using ra...
Efficient comparison whether set of values is between min-max filters
|algorithms|
We want to distribute 3*n known cards among 3 players evenly given a set of constraints that prohibits some players from having certain suits. For example: We want to distribute 1H, 2H, 3S, 4S, 5D, 6D (second letter refers to suit of card) among three players A, B, C such that A does not get any card of suit Heart...
I'm trying to optimize a practical problem in a database query. Suppose we have a db table`Products` and each product has a few numeric properties. I save the properties values in a different table `ProductProperty` table because the user can add more property types. The user wants to look for products using range filt...
_(Disclaimer: I'm not a computer scientist and have not read most of these books. I wish more people would address this interesting question.)_ CS courses often provide an introduction to the field which may be supported by corresponding textbooks. For those various options exist out there. Many of them have titles ...
_(Disclaimer: I'm not a computer scientist and have not read most of these books. I wish more people would address this interesting question.)_ CS courses usually provide an introduction to the field which may be supported by corresponding textbooks, for which various options exist out there. Many of them have title...
A sequence $(a_1,a_2, \dots, a_n) $ and natural numbers $n$ and $k$ are given. We want to calculate the longest increasing subsequence of sequence $(b_1,b_2, \dots, b_n)$ for which there exist an interval of pointers $[l, r]$ and a number $x$, $-k\le x\le k$, such that $b_i = a_i + x$ for $i \in [l, r]$, and $b_i = ...
Consider $X = [x_1, x_2, …, x_{3n}]$ the sequence of cards. For $i \in \{1, …, 3n\}$, denote $s(i)\subseteq \{A, B, C\}$ the set of players allowed to get card $x_i$. For $i\in \{1, …, 3n\}$ and $a, b, c\in \{1, …, n\}$, denote $f(i, a, b, c)$ the number of possibilities to distribute cards $1, …, i$ among $A$, $B$ and...
Build a context-free grammar for the language: > $L=\{\#x\#y\#\,\,;\,\,|x|=|y|\,\,\wedge\,\,x,y\in\{0,1\}^{*}\}$ over $\sum=\{0,1,\#\}$ How can I make sure that |x|=|y|?
Build a context-free grammar for the language
|formal-languages|context-free|
Without giving you all the answer, consider using the following rules (to be completed): > $X \to AXA$ > > $A \to 0 \mid 1$
Consider $X = [x_1, x_2, …, x_{3n}]$ the sequence of cards. For $i \in \{1, …, 3n\}$, denote $s(i)\subseteq \{A, B, C\}$ the set of players allowed to get card $x_i$. For $i\in \{1, …, 3n\}$ and $a, b, c\in \{1, …, n\}$, denote $f(i, a, b, c)$ the number of possibilities to distribute cards $1, …, i$ among $A$, $B$ and...
null
Here's a simple solution that runs in `O(n)` time. To explain the solution, we must make a few observations. First, note that having a negative value of `x` has the same effect as a positive value (ex. having `x = -3` will produce a sequence `b` with the same longest increasing subsequence as `x = 3`) so we should o...
null
Build a context-free grammar for the the complementary language of: > $L=\{ww^{R}\,\,|\,\,w\in\{0,1\}^{*}\}$ I think $L^C$ is the set of all strings that are not palindromes, but I don't know how to start building the grammar.
Build a context-free grammar for the language
|formal-languages|context-free|
Imagine that I have an algorithm written in C that is of, let's say, 10,000 characters in length. Such a program can be simulated on a turing machine (Wikipedia: Anything a real computer can compute, a Turing machine can also compute. For example: "A Turing machine can simulate any type of subroutine found in program...
Upper limit of instructions of a program for a Turing machine that has been converted from a real programming language
|turing-machines|c|
A word in $L^C$ is either a word of odd length or a word $uv$ with $|u| = |v|$ and $v \neq u^R$: $$L^C = L_1 \cup L_2$$ with $L_1 = (\Sigma\Sigma)^*\Sigma$ and $L_2 = \{uv\mid |u| = |v| \text{ and }v\neq u^R\}$. It should be easy for you to find a CFG for $L_1$. As for $L_2$, note that if $u=u_1…u_n$ and $v = ...
You could write a Turing machine that implements a C interpreter, and is less than a googolplex instructions long. Of course you probably wouldn't want to actually do that, as that would be far too tedious and painful. So, for example, perhaps you instead might write a Turing machine that can evaluate any boolean c...
null
Build a context-free grammar for the the complementary language of: > $L=\{ww^{R}\,\,|\,\,w\in\{0,1\}^{*}\}$ I think $L^C$ is the set of all strings that are not palindromes, but I don't know how to start building the grammar. **Attempt:** > S→ A | B > > A→ AAA | 0 | 1 > > B→ 0C1 | 1C0 | 0B0 | 1B1 ...
Databases are not a silver bullet for every problem under the sun. You are asking how to answer multi-dimensional [range searches](https://en.wikipedia.org/wiki/Range_searching) efficiently. Rather than trying to contort your data into a form which lets you solve this with a standard database (a problem for which you...
There are several players at the end of the poker night with wins and losses, with zero sum. What is the optimal solution to settle the balance that minimize the total number of transactions (eg. if we consider a transaction as a venmo payment). name | balance A | -200 B | +100 <- biggest ...
Minimal Number of Transactions to Settle Outstanding Poker Game
|algorithms|graphs|optimization|
null
Given 2 integer $M$ and $N$, a recursive modulo is $M \bmod (M \bmod (M \bmod ...(M \bmod N)$ until the result is 0. What is its time complexity? I guess that it's $O(log(M))$ but I can't prove it.
Complexity of taking recursive modulo
|complexity-theory|time-complexity|number-theory|