instruction stringlengths 0 29.8k ⌀ |
|---|
null |
I second the answers given so far (equality and comparison operators but fulfill the mathematical requirements and not doing so can cause nasty bugs that are hard to spot).
But I want to mention a method that sometimes solves the problem that people try to solve using an invalid comparator like the one mentioned in t... |
null |
null |
null |
null |
I am trying to wrap my head around the concepts of *auto-reducibility* and *having access to an Oracle*.
The way I understand is that a language is auto-reducible iff there is a Turing Machine $M^{L}(x)=1$ for every *x $\in$ L* with the special requirement that on input *x* the Turing Machine is not allowed to query t... |
Showing SAT is auto-reducible |
|turing-machines|oracle-machines|sat-solvers| |
You can reduce from subset-sum as follows: given a set of $n$ positive integers $x_1, \dots, x_n$ and a target $T$, consider an instance with $2$ people $p_1, p_n$ and $n+1$ objects $a_1, \dots, a_{n+1}$. Objects $a_1, \dots, a_n$ are owned by $p_1$ while $a_{n+1}$ is owned by $p_2$.
The valuations are as follows: $v... |
null |
You can reduce from subset-sum as follows: given a set of $n$ positive integers $x_1, \dots, x_n$ and a positive integer target $T$, consider an instance with $2$ people $p_1, p_n$ and $n+1$ objects $a_1, \dots, a_{n+1}$. Objects $a_1, \dots, a_n$ are owned by $p_1$ while $a_{n+1}$ is owned by $p_2$.
The valuations a... |
In the book of Hopcroft-Ullman (the 1979 edition) there is a rule $Da\rightarrow aaD$ in the example of the CSL language $a^{2^i}$.
Valid rules in CSG have the form $\alpha A \beta\rightarrow \alpha\psi\beta$. I think the mentioned rule is not valid, since there is no way to get rid of the terminal $a$ at the right... |
Valid rules in CSG |
|formal-languages|context-sensitive| |
null |
What Hopcroft and Ullman call a context-sensitive grammar is nowadays called a [noncontracting grammar](https://en.wikipedia.org/wiki/Noncontracting_grammar); see page 223. The two types of grammar are equivalent in power. |
Autoreducibility was introduced in Buhrman, Fortnow and Torenvliet, [Using autoreducibility to separate complexity classes](https://ir.cwi.nl/pub/1930/1930D.pdf). Here is the (informal) definition (page 520):
> A set $L$ is autoreducible if there is a polynomial-time oracle Turing machine $M$ that accepts $L$ using $L... |
As stated in the question title, if $f(n)$ has polynomial growth and $g(n)=\mathcal{O}(f(n))$, then how can we show $g(n)$ also has polynomial growth?
$g(n)=\mathcal{O}(f(n))$ gives us $g(n)\leq cf(n)$ for a positive constant $c$ for some $n>n_0>0$. But how can I conclude $g(n)$ also satisfies the polynomial growth ... |
Show if $f(n)$ has polynomial growth and $g(n)=\mathcal{O}(f(n))$, then $g(n)$ also has polynomial growth |
|time-complexity|asymptotics| |
As stated in the question title, if $f(n)$ has polynomial growth and $g(n)=\Theta(f(n))$, then how can we show $g(n)$ also has polynomial growth?
$g(n)=\Theta(f(n))$ gives us $0\leq c_1f(n)\leq g(n)\leq c_2f(n)$ for some positive constants $c_1, c_2$ for some $n>n_0>0$. But how can I conclude $g(n)$ also satisfies t... |
Show if $f(n)$ has polynomial growth and $g(n)=\Theta(f(n))$, then $g(n)$ also has polynomial growth |
I am using the JPS algorithm to find the shortest path from start $S$ to goal $G$ on a binary grid where each cell can be eithe 0 (free) or 1 (obstacle). Now, I would like my algorithm to take into account the distance between the path and the obstacles and to find a path that approximates the shortest, while being "sa... |
To add another perspective on this: there is a class of problems known as [fixed parameter tractable](https://en.wikipedia.org/wiki/Parameterized_complexity#FPT) (FPT) which has been studied extensively. In this area of research, one studies problems that, given a *fixed* additional integer parameter $k$ on the input, ... |
As stated in the question title, if $f(n)$ has polynomial growth and $g(n)=\Theta(f(n))$, then how can we show $g(n)$ also has polynomial growth?
$g(n)=\Theta(f(n))$ gives us $0\leq c_1f(n)\leq g(n)\leq c_2f(n)$ for some positive constants $c_1, c_2$ for some $n>n_0>0$. But how can I conclude $g(n)$ also satisfies t... |
null |
A simple one: Given n chess positions, find an optimal move for each position.
The game of chess is finite, so finding an optimal move for any position is O(1), and for n positions it is O(n). With a huge constant. |
Let us consider only sufficiently large values of $n$. As you have pointed out there are positive constant such that:
$$
c_1 f(n) \le g(n) \le c_2f(n).
$$
Also, since $f$ has polynomial growth, for every $\phi \ge 1$ there exists some $d_\phi > 1$ such that:
$$
\frac{1}{d_\phi} f(n) \le f(\psi n) \le d_\phi f(... |
Minisat and Z3 have the same hack to extract unsat cores. I found the Z3 example easy to understand. The link is here:
https://github.com/Z3Prover/z3/blob/master/examples/c%2B%2B/example.cpp
There are about 4 examples on extracting unsat cores. You can use the code as is by modifying the assertions, if you like ... |
Let us consider only sufficiently large values of $n$. As you have pointed out there are positive constant such that:
$$
c_1 f(n) \le g(n) \le c_2f(n).
$$
Also, since $f$ has polynomial growth, for every $\phi \ge 1$ there exists some $d_\phi > 1$ such that:
$$
\frac{1}{d_\phi} f(n) \le f(\psi n) \le d_\phi f(... |
Let's say that we have a set consisting of many strings encrypted with the same key by a xor cypher, moreover they are the same length as the key, both the key and the original strings might contain only small english letters and the space char.
We have encryption function E(k,m)=k⊕m and decryption D(k,c)=k⊕c, which... |
Recover key from repeating-xor encryption |
|encryption|xor| |
In a graph with `N` nodes, where each node represents a house and is labeled from `0` to `N-1`, an adjacency matrix `graph[i][j]` indicates the distance from node `i` to node `j`.
Consider a list of tuples `[[init_1, target_1], ..., [init_k, target_k]]`, representing delivery requests. Each tuple, like `[[1, 2], [2... |
Optimizing Delivery Routes in a Graph-Based Network to Minimize Maximum Delivery Time |
|algorithms|graphs|optimization|graph-traversal| |
null |
I've been trying to wrap my head around the proof provided in [this][1] answer.
I understand that $P$ is a class where languages can be decided by a Turing Machine and that $P/poly$ is a bigger class that also includes languages that can be decided by circuits.
> Take a language $L$ which is not in $\mathsf{E} = \... |
Showing for decidable language that is in $P/poly$ but not in $P$ (follow-up) |
|complexity-theory| |
I've been trying to wrap my head around the proof provided in [this][1] answer.
I understand that $P$ is a class where languages can be decided by a Turing Machine and that $P/poly$ is a bigger class that also includes languages that can be decided by circuits.
> Take a language $L$ which is not in $\mathsf{E} = \... |
null |
The problem is unlikely to admit any efficient solution since it is NP-Hard even when there is only one delivery person and, for all edges $(u,v)$ in the graph, the distance between $u$ and $v$ is $1$.
To see this let $G=(V, E)$ be the graph and let $V = \{v_1, \dots, v_n\}$.
Construct a new graph $H = (V', E')$ wh... |
Let us consider only sufficiently large values of $n$. As you have pointed out there are positive constant such that:
$$
c_1 f(n) \le g(n) \le c_2f(n).
$$
Also, since $f$ has polynomial growth, for every $\phi \ge 1$ there exists some $d_\phi > 1$ such that:
$$
\frac{1}{d_\phi} f(n) \le f(\psi n) \le d_\phi f(... |
null |
I created a 8-puzzle search solver using BFS, A* with manhattan distance, and A* with misplaced tiles.
I generated data that said that for a particular random board, misplaced tiles did less node expansions to solve the board.
Is this possible?
I thought that manhattan distance is always less node expansions t... |
Manhattan distance always less node expansion than misplaced tiles heuristic? |
|complexity-theory|search-algorithms|artificial-intelligence|heuristics| |
In a graph with `N` nodes, where each node represents a house and is labeled from `0` to `N-1`, an adjacency matrix `graph[i][j]` indicates the distance from node `i` to node `j`.
Consider a list of tuples `[[init_1, target_1], ..., [init_k, target_k]]`, representing delivery requests. Each tuple, like `[[1, 2], [2... |
In a graph with `N` nodes, where each node represents a house and is labeled from `0` to `N-1`, an adjacency matrix `graph[i][j]` indicates the distance from node `i` to node `j`.
Consider a list of tuples `[[init_1, target_1], ..., [init_k, target_k]]`, representing delivery requests. Each tuple, like `[[1, 2], [2... |
Say I have an FPL class problem with the complexity O(2^k * n). If I limit the problem so that k is a known factor (for example 150). Then the complexity becomes O(2^150 * n). I have learnt that constants get removed from the complexity equation. Which means the complexity should now be O(n). Does this mean the limitat... |
FPL class problem into P class problem? |
|time-complexity| |
I was wondering how you would go about making a two-tape Turing machine in linear time that starts with input # on Tape 1, where and are binary integers that might have leading 0's. It would accept the input if and have the same value such as 001101 has the same value as 1101. Would it be a good idea to replace the... |
Turing machine comparing two binary numbers together |
|turing-machines| |
$f$ and $g$ being known functions.
We suppose that the problem is solvable.
To me, for the moment, this question, if a decision problem it is or can be, is more an NP rather than a P problem, because if it was a P problem, we would have to answer it in polynomial time, and so test every $u$ function in a single p... |
Is « Does exist at least one function $u$ such that $f(u(0)) \ne g(u(0))$? » an NP problem? or a P problem? |
|np|decision-problem|p-vs-np| |
Put the machine in a state where the first tape contains $x$ with no leading zeros, and the second tape contains $y$ with no leading zeros, then check that the contents of two tapes are equal.
To reach such state, assume that both $x$ an $y$ contain at least one $1$ (this can be easily checked). Then, scan the first... |
````
L= {abc}
prefix = {epsilon,a,ab,abc}
suffix = {epsilon,c,bc,abc}
````
It's easy to find suffixes and prefixes for finite Regular languages. But what will be the approach for infinite Regular languages?
For example:-
````
Alphabet = {a,b}
L1 = Every string starts with a.
L2 = Every string ends with a.... |
Here is a sketch: Put the machine in a state where the first tape contains $x$ with no leading zeros, and the second tape contains $y$ with no leading zeros, then check that the contents of two tapes are equal.
To reach such state, assume that both $x$ an $y$ contain at least one $1$ (this can be easily checked). Th... |
I'm going to assume that $f:A\to B$ and $g:A\to B$ for some (known) sets $A$ and $B$ and that, given a set $C\ni0$ we are to find a function $u:C\to A$ such that $f(u(0))=g(u(0))$. Of course, this is just the same as asking for an element $a\in A$ such that $f(a)=g(a)$ (consider, for instance, the constant function $u(... |
null |
Turing machine comparing two binary numbers in linear time |
We consider a partially filled starting grid, where $n^2$ is the side size of the grid, $m$ is the number of non-empty initial squares, $f$ is the function that places randomly initially the integers into the squares of the grid, the $((x_i,y_i))$ are the coordinates of the initial non-empty squares, $p_i$ are the init... |
How to formulate "The general Sudoku problem is in P" formally and rigorously? How to calculate then the input size? |
|complexity-theory|decision-problem|sudoku| |
i would like to perform a reduction for my novel problem to preferably the set cover problem, but i am a bit lost..
My problem can be described as follows:
Suppose you have given an binary word as input =101101…, an integer and a set of smaller binary words $_1,_2,…,_$
with $length(w)$ is a strict divisor of $l... |
Reduction from novel problem to Set Cover |
|reductions|polynomial-time-reductions|set-cover| |
For regular languages this is relatively straighforward. Let $L\subseteq\Sigma^*$ be regular. Let $A = (Q, \Sigma, q_0, \delta, F)$ be an NFA that recognises $L$. Construct another NFA $A' = (Q, \Sigma, q_0, \delta, F')$ from $A$ by changing just the final state set as follows: set $F'$ to the set of all states in $Q$ ... |
i would like to perform a reduction for my novel problem to preferably the set cover problem, but i am a bit lost..
My problem can be described as follows:
Suppose you have given an binary word as input =101101…, an integer and a set of smaller binary words $_1,_2,…,_$
with $length(w)$ is a strict divisor of $l... |
Let us consider only sufficiently large values of $n$. As you have pointed out there are two constants $c_1, c_2$ with $0< c_1 \le c_2$ such that:
$$
c_1 f(n) \le g(n) \le c_2f(n).
$$
Also, since $f$ has polynomial growth, for every $\phi \ge 1$ there exists some $d_\phi > 1$ such that:
$$
\frac{1}{d_\phi} f(n... |
i would like to perform a reduction for my novel problem to preferably the set cover problem, but i am a bit lost..
My problem can be described as follows:
Suppose you have given an binary word as input =101101…, an integer and a set of smaller binary words $_1,_2,…,_$
with $length(w)$ is a strict divisor of $l... |
Define “correctly sorted”. Here’s an attempt: An array is k-sorted if $a_i <= a_j$ whenever $i <= j <= i+k$. If <= is transitive then any 1-sorted array is (n-1)-sorted.
With the definition of <= in the question, assume the array contains one element equal to zero, one element equal to 1+epsilon, and all other elem... |
I was trying to figure out how can I construct a non-deterministic Turing machine that decides the language $L = \{0^{n^2} | n \geq 1\}$
I looked at some of the proposed solutions here :
https://cs.stackexchange.com/questions/41416/turing-machine-for-unary-encoded-quadratic-numbers
and here:
https://cs.stac... |
Non-deterministic Turing machine that decides the language $L = \{0^{n^2} | n \geq 1\}$ |
|turing-machines|decision-problem|nondeterminism| |
In Java, I'm getting the error for all my return statements that I can't return a value with a void result type, but I don't declare the return type as void anywhere, and I'm really not sure what the issue is. Here's my code:
public class Card {
private int suit;
private int rank;
public Card(int ... |
"Cannot return a value from a method with void result type" but it's not void? |
|java| |
null |
As you know, big O notation hides all constants. For instance, both runtimes $T_1=n$ and $T_2=10^{10}n$ are considered to be linear ($\mathcal{O(n)}$).
Is there an iconic problem whose best known solution has a terrible (large) constant in the runtime expression? |
Is there a known polynomial time complexity problem with bad constants? |
null |
You didn't close the paranthesis in the Card() constructor:
public Card(int suit, int rank) {
this.suit = suit;
this.rank = rank;
} // missed
Other than that everything is fine. |
null |
A set of n independent tasks, each having integer execution times,
are to be executed using three identical processors. A task can be
executed in any of the three processors. Develop a sequential
algorithm to find minimal total execution time for scheduling all the
tasks. For this develop an initial recursive defin... |
3 Processor Scheduling |
|algorithms|np-complete|dynamic-programming|scheduling|p-vs-np| |
i would like to perform a reduction for my novel problem to preferably the set cover problem, but i am a bit lost..
My problem can be described as follows:
Suppose you have given an binary word as input =101101…, an integer and a set of smaller binary words $_1,_2,…,_$
with $length(w)$ is a strict divisor of $l... |
I was trying to figure out how can I construct a non-deterministic Turing machine that decides the language $L = \{0^{n^2} | n \geq 1\}$
I looked at some of the proposed solutions here :
https://cs.stackexchange.com/questions/41416/turing-machine-for-unary-encoded-quadratic-numbers
and here:
https://cs.stac... |
I'm aware that the worst case scenario recurrence relation corresponding equation is:
$$
T(n) = T(n-1) + T(0) + \Theta(n)
$$
However, I really don't get how the last term $ \Theta(n)$ was determined.
1. I dont understand why $ \Theta(n)$ and not $ \mathcal{O}(N) $
2. I don't get why it is $ \Theta(N) $ and... |
Worst Case Scenario Quick Sort |
|algorithms|quicksort| |
null |
The [FLP paper][1] provides proof in section "4. Initially Dead Processes" that consensus is possible if majority of processes live and no process dies during the consensus protocol. The proof has 4 main steps:
1. Build G graph in way that each process broadcast it's process number and waits for the message from L... |
null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.