instruction
stringlengths
0
29.8k
⌀
Dynamic programming gives an $O(n^2)$ solution. Consider partitioning the array recursively to compute the scores of each possible partition. In particular, notice that $$ OPT = \min_t \text{score}([a_1, ..., a_t]) + \text{score}([a_{t+1}, ..., a_n]) $$ This naturally leads us to a recursive approach. m...
{"Voters":[{"Id":154933,"DisplayName":"Krish Singal"}]}
Dynamic programming gives an $O(n^2)$ solution. Consider partitioning the array recursively to compute the scores of each possible partition. In particular, notice that $$ OPT = \min_t \text{score}([a_1, ..., a_t]) + \text{score}([a_{t+1}, ..., a_n]) $$ This naturally leads us to a recursive approach. m...
Dynamic programming gives an $O(n^2)$ solution. Consider partitioning the array recursively to compute the scores of each possible partition. In particular, notice that $$ OPT([a_1, ..., a_n]) = \min_t \text{score}([a_1, ..., a_t]) + OPT([a_{t+1}, ..., a_n]) $$ This naturally leads us to a recursive approach. ...
Dynamic programming gives an $O(n^2)$ solution. Consider partitioning the array recursively to compute the scores of each possible partition. In particular, notice that $$ OPT([a_1, ..., a_n]) = \min_t \text{score}([a_1, ..., a_t]) + OPT([a_{t+1}, ..., a_n]) $$ This naturally leads us to a recursive approach. ...
In my sens, Proving NP-Completeness of a problem, can let you try general solutions. There are some general or maybe efficient (easy to implement and customize, more understandable or representative, scalable, a better parallel version) solutions for any problem. By term "general solutions", i mean interpolation, mo...
Turing completeness is *not* a property of a single program or a single machine. It **does not make sense** to ask “is this machine/program/gadget Turing-complete?” Turing-completeness is a property of a **model of computation**, which is a mathematical structure that describes a particular way of performing computa...
I was solving a coding question which boiled down to this problem.\ Given a bipartite graph $G=\{V\cup U,E\}$. There is a positive value given for every node in $U$.\ Now we have to find the matching in which the sum of value of every node in $U$ which is also in the matching is maximum.\ Consider an example, Let v...
Maximum weighted matching in Bipartite Graph
|graphs|bipartite-matching|
First let $Y = \{ a^i b^j \mid i,j>0\}$.You are looking for $\Sigma^* \setminus Y$, the complement of $Y$. As you state this consists of all strings having a $b$ before an $a$, or having only $a$ or only $b$'s. Your second solution ("if there exists a $b$ then there is an $a$ at a later position") does not seem to cove...
Andrej Bauer rightly points out that in general, it does not make sense to ask whether a particular machine/program/gadget is Turing complete. However, it does make sense when such a device is *programmable*: when it can read a specification of what it needs to do, and then do that. In other words: when it implement...
## Question Description I’m facing a problem asking me to construct a (Determine) Turing Machine that can accept such a language: $L = \{ w \in \{a,b\}^* | \mbox{for any non-empty prefix $w'$ of $w$}, n_a(w') > n_b(w')\}$ The problem isn’t expressed in English originally. To make sure I’m translating correctly...
null
You can build a two tape machine machine. The first tape will contain the input string, while the second tape will act as a counter. The machine will work in at most $|w|$ phases, indexed from $1$. In the generic $i$-th phase it will check that $n_a(w_i) > n_b(w_i)$, where $w$ is the prefix of the input containing t...
## Question Description I’m facing a problem asking me to construct a (deterministic) Turing Machine that can accept such a language: $L = \{ w \in \{a,b\}^* \mid \mbox{for any non-empty prefix $w'$ of $w$}, n_a(w') > n_b(w')\}$ The problem isn’t expressed in English originally. To make sure I’m translating co...
Construct a Turing machine that accepts strings $w \in \{a,b\}^*$ such that any non-empty prefix $w'$ of $w$ has $n_a(w') > n_b(w')$
You can build a two-tape Turing machine quite easily. The first tape will contain the input string, while the second tape will act as a counter. The machine will work in at most $|w|$ phases, indexed from $1$. In the generic $i$-th phase it will check that $n_a(w_i) > n_b(w_i)$, where $w$ is the prefix of the input ...
You can turn the problem into an edge-weighted variant by setting the weight on edge $vu$ to be $\texttt{valueArray}(u)$ where $\texttt{valueArray}(u)$ is the value of $u \in U$. Now a maximum weight matching in this graph is a matching which maximizes the sum of the values of the nodes in $U$.
Imagine a Problem $A$ with input size $n$ for which you can get a proof certificate (polynomial number of bits). Next you try to use this string to verify if your problem is solved or not. You know that verification gets almost as good as if you'd try to verify an $NP$-problem in the sense that the verification p...
An operator can be described in terms of three things: * The accepted range of values (type) of each of its operands * Its behaviour * The possible values (type) of its result The simplest "or" operator is defined as having two operands and a result all with values "true" or "false", i.e. a "boolean" type. With...
null
An operator can be described in terms of three things: * The accepted range of values (type) of each of its operands * Its behaviour * The possible values (type) of its result The simplest "or" operator is defined as having two operands and a result all with values "true" or "false", i.e. a "boolean" type. With...
While working through the book Parameterized Complexity Theory of Flum and Grohe, I encountered exercise 1.42: Let $H = (V, E)$ be a hypergraph. A basis of $H$ is a set $S$ of subsets of $V$ with the property that for all $e \in E$ there are $s_1, \dots, s_\ell \in S$ such that $e = s_1 \cup \dots \cup s_\ell$. The ...
Imagine a Problem $A$ with input size $n$ for which you can get a proof certificate (polynomial number of bits). Next you try to use this string to verify if your problem is solved or not. You know that verification gets almost as good as if you'd try to verify an $NP$-problem in the sense that the verification p...
You can turn the problem into an edge-weighted variant by setting the weight on edge $vu$ to be $\texttt{valueArray}(u)$ where $w(vu) = \texttt{valueArray}(u)$ is the value of $u \in U$. Now a maximum weight matching in this graph is a matching which maximizes the sum of the values of the nodes in $U$. Note that yo...
First let $Y = \{ a^i b^j \mid i,j>0\}$.You are looking for $\Sigma^* \setminus Y$, the complement of $Y$. As you state this consists of all strings having a $b$ before an $a$, or having only $a$ or only $b$'s. Your second solution ("if there exists a $b$ then there is an $a$ at a later position") does not seem to cove...
If you don't care about the number of symbols in the alphabet, then there are constructions of universal Turing machines that only use $2$ [states][1].* This means that every Turing machine with at least $3$ states admits an equivalent Turing machine with less states. Turing machines with just two states don't adm...
null
**Problem description:** <br/> Given a P-time function(program) pchk:{0,1} ⃰ -> {0,1}. A function f,<br/> f:pchk×ℕ -> {0,1}: f can only simulate pchk with arbitrary argument x.<br/> And, f(pchk,n)==1 iff ∃x, |x|<=n, pchk(x)==1.<br/> <br/> Obviously, the time complexity of f is in O(2^N) (the length of pchk can be<...
Proof About P!=NP
|complexity-theory|
First let $Y = \{ a^i b^j \mid i,j>0\}$.You are looking for $\Sigma^* \setminus Y$, the complement of $Y$. As you state this consists of all strings having a $b$ before an $a$, or having only $a$ or only $b$'s. Your second solution ("if there exists a $b$ then there is an $a$ at a later position") does not seem to cove...
Alright, I think I finally found what I was searching for. What I was trying to describe turns out to be the complexity class $MA$ because the proof is of polynomial size and we use the full proof and a polynomial amount of bits. It's similar to $NP$ but since we don't know whether $MA=NP$, only that $NP\subseteq MA$ ...
Alright, I think I finally found what I was searching for. What I was trying to describe turns out to be the complexity class $MA$ because the proof is of polynomial size and we use the full proof and a polynomial amount of bits. It's similar to $NP$ but since we don't know whether $MA=NP$, only that $NP\subseteq MA$,...
We are running a restaurant. Unfortunately due to mysterious reasons, we cannot tell our chef what **recipes** to make, we can only prepare him the **ingredients** for the meals. Fortunately our chef has memorized all possible **recipes**, therefore if we carefully designate separate **tables** on which we put **recipe...
Separate recipes into compatible categories
|algorithms|graphs|colorings|
You didn't prove any lower bound here, which is required to imply that $P\neq NP$, but rather you have shown an upper bound. So essentially you have shown that the problem is in $Exp$ but you haven't proven that the problem is *not* in $P$
{"Voters":[{"Id":79440,"DisplayName":"Nathaniel"},{"Id":755,"DisplayName":"D.W."}]}
null
> A key breakthrough is that the author of the best selling book on the > theory of computation MIT professor Michael Sipser has agreed that the > following verbatim paragraph is correct: > > If simulating halt decider H correctly simulates its input D until H > correctly determines that its simulated D would ne...
Simulating Halt Decider Applied to the Halting Theorem
Turing completeness is *not* a property of a single program or a single machine. It **does not make sense** to ask “is this machine/program/gadget Turing-complete?” Turing-completeness is a property of a **model of computation**, which is a mathematical structure that describes a particular way of performing computa...
I am solving a problem that involves finding a `pow(x, n)` without using a `pow` library function. Following is the algorithm that works (apart from negative `n` and some edge cases) but trying to understand the math logic behind it. ``` 2^5 -> x = 2, n = 5 (101) ``` The idea is to multiply the answer with `2 ...
Finding the power of a number without a library pow function
|algorithms|
First let $Y = \{ a^i b^j \mid i,j>0\}$.You are looking for $\Sigma^* \setminus Y$, the complement of $Y$. As you state this consists of all strings having a $b$ before an $a$, or having only $a$ or only $b$'s. Your second solution ("if there exists a $b$ then there is an $a$ at a later position") does not seem to cove...
Let $k$ be the number of binary digits of $n$ and let $n_i$ denote the $i$-th least significant digit in the binary representation of $n$, counting from $1$. $$n = \sum_{i=1}^{k} n_i 2^{i-1}$$ Therefore: $x^n = x^{\sum_{i=1}^{k} n_i 2^{i-1}} = \prod_{i=1}^{k} x^{n_i 2^{i-1}}$. At the beginning of the $j$-th i...
According to O'Donnell's book ``Analysis of Boolean Functions", in order to determine the Fourier coefficient of a boolean function $f$ on a subset $S$, we take an inner product of $\chi_S$ and $f$ and then divide the result by $2^n$. In the paper by Beigel [1], a different formula is given. Specifically, $c_{S}^{fouri...
Formula for computing a specific Fourier coefficient of a boolean function
|complexity-theory|fourier-transform|boolean-complexity|
{"Voters":[{"Id":16034,"DisplayName":"Yves Daoust"},{"Id":6759,"DisplayName":"Steven"},{"Id":79440,"DisplayName":"Nathaniel"}]}
null
Given two disjoint rectangles $(a,b]\times (c,d]$ and $(e,f]\times (g,h]$ in $\mathbb{R}^2$ how can I check with a decision tree of least depth if a given point $(x,y)$ lies within the union of the rectangles? I think that I need 4 decisions to check if $x$ is within $(\min(a,e),\max(b,f)]$ and if $y$ is within $(\m...
Decision tree to check 2 rectangles
|algorithms|binary-trees|decision-problem|
To prove that a new language is Turing-complete the authors need to show that it can simulate any other (already known) Turing-complete language. I wonder what Turing-complete language is the simplest to simulate? [Bitwise Cyclic Tag][1] looks very easy. Are there better candidates? [1]: https://esolangs.org/...
If no preprocessing of the rectangles is allowed, in the worst case you need $8$ comparisons, full stop. That's because there are $8$ independent coordinates and the answer depends on them. If preprocessing is allowed, you can determine a vertical or horizontal line by one of the vertices such that separates the two...
If no preprocessing of the rectangles is allowed, in the worst case you need $8$ comparisons, full stop. That's because there are $8$ independent coordinates and the answer depends on them. If preprocessing is allowed, you can determine a vertical or horizontal line by one of the vertices that separates the two rect...
If no preprocessing of the rectangles is allowed, in the worst case you need $8$ comparisons, full stop. That's because there are $8$ independent coordinates and the answer depends on them. If preprocessing is allowed, you can determine a vertical or horizontal line by one of the vertices that separates the two rect...
If no preprocessing of the rectangles is allowed, in the worst case you need $8$ comparisons, full stop. That's because there are $8$ independent coordinates and the answer depends on them. ---------- If preprocessing is allowed, you can determine a vertical or horizontal line by one of the vertices that sepa...
If no preprocessing of the rectangles is allowed, in the worst case you need $8$ comparisons, full stop. That's because there are $8$ independent coordinates and the answer depends on them. ---------- If preprocessing is allowed, you can determine a vertical or horizontal line by one of the vertices that sepa...
Using C-like pseudo-program:<br/> **Definition**: bool S(Func, UInt): S(f,n)==true iff ∃x, x<=n, F(x)==true <br/> F is defined in ℙ as a certificate function, so S is in ℕℙ. <br/> <br/> Now, if S∈ℙ, then, there exists a function F∈ℙ: <br/> bool F(UInt n) { <br/> return !S(F,n); <br/> } <br/> <br/> Given an ...
A Proof That ℙ≠ℕℙ
|complexity-theory|time-complexity|complexity-classes|
You may or may not have shown that one particular function doesn't provide valid certificates (may or may not because it's not quite clear what you are saying). That's true for most functions. You haven't shown that no function _can_ be used.
null
|recursion|arrays|
null
null
$\mathsf{P}$, $\mathsf{NP}$ or $\mathsf{EXP}$ are not sets of functions, but sets of problems. As an example, consider the following problem $\texttt{SORTED}$: > Input: an array $a = [a_1, …, a_n]$. > > Question: is $a$ a sorted array? This problem can easily be solved by a polynomial function, something that w...
$\mathsf{P}$, $\mathsf{NP}$ or $\mathsf{EXP}$ are not sets of functions, but sets of problems. As an example, consider the following problem $\texttt{SORTED}$: > Input: an array $a = [a_1, …, a_n]$. > > Question: is $a$ a sorted array? This problem can easily be solved by a polynomial time function, something t...
While working through the book Parameterized Complexity Theory of Flum and Grohe, I encountered exercise 1.42: Let $H = (V, E)$ be a hypergraph. A basis of $H$ is a set $S$ of subsets of $V$ with the property that for all $e \in E$ there are $s_1, \dots, s_\ell \in S$ such that $e = s_1 \cup \dots \cup s_\ell$. The ...
Using C-like pseudo-program:<br/> **Definition**: bool S(Func, UInt): S(f,n)==true iff ∃x, x<=n, F(x)==true <br/> F is defined in ℙ as a certificate function, so S is in ℕℙ. <br/> <br/> Now, if S∈ℙ, then, there exists a function F∈ℙ: <br/> bool F(UInt n) { <br/> return !S(F,n); <br/> } <br/> <br/> Given an ...
A (False) Proof That ℙ≠ℕℙ
Using C-like pseudo-program:<br/> **Definition**: bool S(Func, UInt): S(f,n)==true iff ∃x, x<=n, F(x)==true <br/> F is defined in ℙ as a certificate function, so S is in ℕℙ. <br/> <br/> Now, if S∈ℙ, then, there exists a function F∈ℙ: <br/> bool F(UInt n) { <br/> return !S(F,n); <br/> } <br/> <br/> Given an ...
$\mathsf{P}$, $\mathsf{NP}$ or $\mathsf{EXP}$ are not sets of functions, but sets of problems. As an example, consider the following problem $\texttt{SORTED}$: > Input: an array $a = [a_1, …, a_n]$. > > Question: is $a$ a sorted array? This problem can easily be solved by a polynomial time function, something t...
**Why the following proof is invaid?** Using C-like pseudo-program:<br/> **Definition**: bool S(Func, UInt): S(f,n)==true iff ∃x, x<=n, F(x)==true <br/> F is defined in ℙ as a certificate function, so S is in ℕℙ. <br/> <br/> Now, if S∈ℙ, then, there exists a function F∈ℙ: <br/> bool F(UInt n) { <br/> return ...
In case the **7** was entered accidentally, and the question was whether a max flow can be computed in time $O(m)$ provided that we have a max flow already, and simply increase all capacities by one. The answer is that the best max flow algorithm is $\omega(m)$ for graphs of unit capacities, which means that if you ...
In the standard framing of the traveling salesman problem, we're given a complete graph, meaning every pair of vertices has an edge in between them. And this might be close to accurate when the salesman is flying between cities. If he's driving however, road networks tend not to be dense. You can drive from any city to...
Traveling salesman problem on an incomplete graph
|graphs|np|approximation|traveling-salesman|
In many computer architecture books (e.g. Computer Organization and Design), the memory layout that is *seen* by a program is as the following figure. [![enter image description here][1]][1] But I wonder about multitask computers, in which many programs execute simultaneously, how the memory layout is. Is the l...
Is the memory layout actual or virtual?
|computer-architecture|
Let $G$ be your original graph and let $G'$ be its transitive closure. Let $C'$ be an optimal tour in $G'$, and let $C$ be the tour in which you replace each edge $(u,v)$ of $C'$ with a shortest path between $u$ and $v$ in $G$. The tour $C$ is optimal in $G$ (even if it visits a city more than once). To see this,...
In the standard framing of the traveling salesman problem, we're given a complete graph, meaning every pair of vertices has an edge in between them. And this might be close to accurate when the salesman is flying between cities. If he's driving however, road networks tend not to be dense. You can drive from any city to...
|dynamic-programming|recursion|arrays|
Let $G$ be your original graph and let $G'$ be its transitive closure. Let $C'$ be an optimal tour in $G'$, and let $C$ be the tour in which you replace each edge $(u,v)$ of $C'$ with a shortest path between $u$ and $v$ in $G$. The tour $C$ is optimal in $G$ (even if it visits a city more than once). To see this,...
Given an ordered sequence of $n$ elements, you have to choose a family $A$ of subsets of consecutive elements, such that each subset of consecutive elements (not necessairly in $A$) can be represented as a disjoint union of at most $k$ elements of $A$. Let $A$ be the minimal set with this property, define the function ...
Function which describes an optimal data structure for a bounded number of query operations?
|complexity-theory|data-structures|
So, consider I have a toy imperative language which ofcourse supports assignment operations. I want to convert each statement of this language into an equivalent turing machine transition. So, the operation ```y:=x``` can where I have ```y``` and ```x``` spread out on a tape (with ```>``` marking the start and a trail ...
How to make a turing transducer for assignment operation, ```y := x```?
|turing-machines|
How to make a turing transducer for assignment operation, y := x?
So, consider I have a toy imperative language which ofcourse supports assignment operations. I want to convert each statement of this language into an equivalent turing machine transition. So, the operation ```y:=x``` can where I have ```y``` and ```x``` spread out on a tape (with ```>``` marking the start and a trail ...
Very simple via dynamic programming (which is just a big name for a very simple principle). If you have one single array element, you have no choice but taking that element as the only subarray. If you have k ≥ 2 array elements, then you can take all k elements as the only subarray. Or you take 1 element as the...
null