instruction stringlengths 0 29.8k ⌀ |
|---|
Is 2-coloring in NL or L? |
|complexity-theory|graphs|complexity-classes|colorings| |
null |
I know what P-hard means.
Let's denote the P-hard problem as H. For any problem A in P, there exists a polynomial-time reduction from A to H.
I think the answer is yes (I suppose that every "easy" problem can be reduced to a "harder" problem (in this case problems in P to an NP-complete problem), but I am not sure. |
The Hamiltonian cycle problem is P-hard? |
|complexity-theory|complexity-classes| |
I`m currently doing my homework that solving TSP using DP algorithm or branch and bound algorithm or backtracking algorithm only to solve up to 40 vertices and I can solve up to 30 vertices when I try 35, it get bad_alloc at memory location 0x00000059F29EEB30. I try to figure out the algorithm but it doesn't get any be... |
How to get the TSP using DP algorithm can use 40 vertices? |
|dynamic-programming|traveling-salesman|search-problem| |
The Hamiltonian cycle problem is $\mathsf{NP}$-Hard (w.r.t. poly-time reductions), that means that there is a Karp reduction from any problem in $\mathsf{NP}$ to Hamiltonian cycle.
Since $\mathsf{P} \subseteq \mathsf{NP}$ the same holds true for any problem in $\mathsf{P}$. Therefore Hamiltonian cycle is $\mathsf{P}... |
If yes, could you say an example?
P=NP would result in NP problems being solvable in polynomial time, but there would still be problems in the EXPTIME class.
|
Is there a decidable problem that we know for sure cannot be solved in polynomial time? |
|complexity-theory|complexity-classes| |
It is known that P $\ne$ EXPTIME. Therefore, any [EXPTIME-complete problem](https://en.wikipedia.org/wiki/EXPTIME#EXPTIME-complete) suffices. For instance: given a deterministic Turing machine $M$, an input $x$, and a positive integer $k$ (represented in binary), determine whether $M$ halts on input $x$ within at mos... |
null |
Imagine two vectors $V=[v_1, v_2, \ldots, v_n]$, $S=[s_1, s_2, \ldots, s_n]$ where $S$ is a rearrangement of $V$ based on some relation $\leq$. Imagine that, instead of computing $S$ using as input $V$ and $\leq$, and want to returns an index map $Idx$. There are two possibilities, where:
1. $Idx[i] = j$ means that ... |
Names for two different index maps for rearrange a sequence |
|sorting|cpu-cache| |
The code provided uses dynamic programming on travelling salesman problem, which has a time complexity of $O(2^n n^2)$, better than $O(n!)$ for brute force but very slow for $n = 40$. Worse is that it has a space complexity of $O(2^n n)$ for memoization, which would require RAM in the terabytes. It is not known whether... |
null |
I am practicing paging in virtual memory and came across a question with the following details
- 44-bit address space
- 16KB page size
- 16 Bytes Page table entry (PTE)
If I understand paging correctly then there would be 2^30 pages, and the page table size if 2^44 bytes
My questions is, do I use a single-lev... |
Do I need a multilevel page table in the following design? |
|virtual-memory|paging| |
What quality of randomness do you need? You can construct [a Linear Congruential Generator](https://en.wikipedia.org/wiki/Linear_congruential_generator) as a PRNG with period of `N` (or the next prime above `N`) and discard out-of-range samples.
Use `rand()` only to seed your LCG PRNG. Of course you get the same s... |
If I start with $n$ different points $P_1,\ldots,P_n \in \mathbb{R}^2$ and want to select a set $X$ of cardinality $m \leqslant n$ from them subject to the condition that the value
$$d_\text{min}(X) = \min_{P, Q \in X, P \neq Q} d_\text{eucl}(P,Q)$$
is maximized by my choice of $X$, then I understand, that this a... |
Max min diversity on points taken from line segments in the plane |
|optimization|computational-geometry| |
{"OriginalQuestionIds":[115309],"Voters":[{"Id":-1,"DisplayName":"Community","BindingReason":{"DuplicateApprovedByAsker":""}}]} |
Yeah, you probably do. The total size of the page table is $2^{30}\cdot2^4=2^{34} = 16GB$. Clearly prohibitively large. A better arrangement would be a three-level page table, where each level maps ten bits of the virtual address. Since each entry is 16 bytes, the size of a page table for one level is $2^4\cdot2^{10} =... |
Ṃųỻịgǻňạcểơửṩ mentioned that this is the [reservoir problem][1]. The reservoir sampling problem, though, is explicitly a very strict requirement for a [streaming algorithm][2], i.e. it works in just one pass over a stream of values whose eventual size we don't know.
In this case, we want to do it in one pass, but we... |
Following the comments, below is a sketch of the proof that shows explicitly that there is no need for the coins to be public, as we can iterate over all random choices in polynomial space.
Sketch of the proof that $\text{IP} \subseteq \text{PSAPCE}$: consider a language $L \in \text{IP}$, and let $(P, V)$ be an int... |
Following the comments, below is a sketch of the proof that shows explicitly that there is no need for the coins to be public, as we can iterate over all random choices in polynomial space.
Sketch of the proof that $\text{IP} \subseteq \text{PSAPCE}$: consider a language $L \in \text{IP}$, and let $(P, V)$ be an int... |
Following the comments, below is a sketch of the proof that shows explicitly that there is no need for the coins to be public, as we can iterate over all random choices in polynomial space.
Sketch of the proof that $\text{IP} \subseteq \text{PSAPCE}$: consider a language $L \in \text{IP}$, and let $(P, V)$ be an int... |
Following the comments, below is a sketch of the proof that shows explicitly that there is no need for the coins to be public, as we can iterate over all random choices in polynomial space.
Sketch of the proof that $\text{IP} \subseteq \text{PSAPCE}$: consider a language $L \in \text{IP}$, and let $(P, V)$ be an int... |
Following the comments, below is a sketch of the proof that shows explicitly that there is no need for the coins to be public, as we can iterate over all random choices in polynomial space.
Sketch of the proof that $\text{IP} \subseteq \text{PSAPCE}$: consider a language $L \in \text{IP}$, and let $(P, V)$ be an int... |
null |
What quality of randomness do you need? You can construct [a Linear Congruential Generator](https://en.wikipedia.org/wiki/Linear_congruential_generator) as a PRNG with period of `N` (or the next prime above `N`) and discard out-of-range samples.
Use `rand()` only to seed your LCG PRNG. Of course you get the same s... |
Given an array of size $n$ that has the item of the heap. To remove an arbitrary element from the heap we would need $O(n)$ to find the element and then $O(logn)$ to reheapify if I am commrect, which means total time complexity is $O(n + logn)=O(n)$. In study notes, I saw it's written $O(nlogn)$, which does not make se... |
Time complexity to remove an item from the heap |
|data-structures|heaps|heap-sort| |
What quality of randomness do you need? You can construct [a Linear Congruential Generator](https://en.wikipedia.org/wiki/Linear_congruential_generator) as a PRNG with period of `N` (or the next prime above `N`) and discard out-of-range samples.
Use `rand()` only to seed your LCG PRNG. Of course you get the same s... |
null |
You can do it in one call to the *rand()* function if you're willing to use large integers.
There are (N K) = N!/(K!(N-K)!) ways to choose K distinct integers from the set [0, N-1], so *rand(M)* will choose a unique subset of K integers in the range [0, N-1], when M = (N K).
It's subtle, but it definitely works. ... |
You can do it in **one** call to the *rand()* function if you're willing to use large integers.
There are (N K) = N!/(K!(N-K)!) ways to choose K distinct integers from the set [0, N-1], so *rand(M)* will choose a unique subset of K integers in the range [0, N-1], when M = (N K).
It's subtle, but it definitely wor... |
You can do it in **one** call to the *rand()* function if you're willing to use large integers.
There are (N K) = N!/(K!(N-K)!) ways to choose K distinct integers from the set [0, N-1], so *rand(M)* will choose a unique subset of K integers in the range [0, N-1], when M = (N K).
It's subtle, but it definitely wor... |
You can do it in **one** call to the *rand()* function if you're willing to use large integers.
There are M = (N K) = N!/(K!(N-K)!) ways to choose K distinct integers from the set [0, N-1], so *rand(M)* will choose a unique subset of K integers from the range [0, N-1].
It's subtle, but it definitely works. You ju... |
You can do it in **one** call to the *rand()* function if you're willing to use large integers.
There are M = (N K) = N!/(K!(N-K)!) ways to choose K distinct integers from the set [0, N-1], so *rand(M)* will choose a unique subset of K integers from the range [0, N-1].
It's subtle, but it definitely works. You ju... |
Performance considerations of index maps for rearranging a vector |
For an NFA with langauge: {w ∈ {0, 1}?: the length of w is odd but not a multiple of three}. How many states are required?
This is the work I have come up with so far:
q0: non-accepting state - because of even length
q1: accepting state - because odd length and not multiple of 3
q2: non-accepting state - because ... |
For an NFA with langauge: {w ∈ {0, 1}?: the length of w is odd but not a multiple of three}. How many states are required? |
|theory| |
For an NFA with langauge: {w ∈ {0, 1}*: the length of w is odd but not a multiple of three}. How many states are required?
This is the work I have come up with so far:
q0: non-accepting state - because of even length
q1: accepting state - because odd length and not multiple of 3
q2: non-accepting state - because ... |
You can do it in **one** call to the *rand()* function if you're willing to use large integers.
There are M = (N K) = N!/(K!(N-K)!) ways to choose K distinct integers from the set [0, N-1], so *rand(M)* will choose a unique subset of K integers from the range [0, N-1].
It's subtle, but it definitely works. You ju... |
You can do it in **one** call to the *rand()* function, with a perfect uniform distribution, if you're willing to use large integers.
There are M = (N K) = N!/(K!(N-K)!) ways to choose K distinct integers from the set [0, N-1], so *rand(M)* will choose a unique subset of K integers from the range [0, N-1].
It's s... |
You can do it in **one** call to the *rand()* function, with a perfect uniform distribution, if you're willing to use large integers.
There are M = (N K) = N!/(K!(N-K)!) ways to choose K distinct integers from the set [0, N-1], so *rand(M)* will choose a unique subset of K integers from the range [0, N-1].
It's s... |
You can do it in **one** call to the *rand()* function, with a perfect uniform distribution, if you're willing to use large integers.
There are M = (N K) = N!/(K!(N-K)!) ways to choose K distinct integers from the set [0, N-1], so *rand(M)* will choose a unique subset of K integers from the range [0, N-1].
It's s... |
What quality of randomness do you need? You can construct [a Linear Congruential Generator](https://en.wikipedia.org/wiki/Linear_congruential_generator) as a PRNG with period of `N` (or the next prime above `N`) and discard out-of-range samples.
Use `rand()` only to seed your LCG PRNG.
Of course you get the same... |
You can do it in **one** call to the *rand()* function, with a perfect uniform distribution, if you're willing to use large integers.
There are M = (N K) = N!/(K!(N-K)!) ways to choose K distinct integers from the set [0, N-1], so *rand(M)* will choose a unique subset of K integers from the range [0, N-1].
It's s... |
If you care only about having uniform probability for each of the $N$ elements to be included in the $K$-element sample, then @PeterCordes's suggestion to use just one call to $rand()$ to seed a suitably tuned LCG is very attractive.
If it is additionally important to have equal probability of each of the $\tbinom... |
We are given an undirected graph $G(V, E)$, where $n = |V|$. The task is to find a bijective function $\psi: V \rightarrow \lbrace{1, 2, \dotsc, n \rbrace}$ such that the following objective is minimized: $\sum_{(u, v) \in E} \max(\psi(u), \psi(v))$. I am interested in the complexity of this problem. Note that this pro... |
A variant of vertex labeling problem |
|complexity-theory|vertex-labeling| |
We are given an undirected graph $G(V, E)$, and let $n = |V|$. The task is to find a bijective function $\psi: V \rightarrow \lbrace{1, 2, \dotsc, n \rbrace}$ such that the following objective is minimized: $\sum_{(u, v) \in E} \max(\psi(u), \psi(v))$. I am interested in the complexity of this problem. Note that this p... |
You can do it in **one** call to the *rand()* function, with a perfect uniform distribution, if you're willing to use large integers.
Here's the basic idea:
1. List out all of the possible ways to choose K distinct integers from the range [0, N-1].
2. Throw a dart at the list, choosing *one* of those ways--using a... |
Yes, that is correct. O(n) to find an arbitrary item, O(log n) to remove it, total O(n).
If you often remove arbitrary items, say you insert n items, then remove the largest or a random item each n/2 times, then the total will be quite large. In this case you could consider a different approach: Mark items as “rem... |
You can do it in **one** call to the *rand()* function, with a perfect uniform distribution, if you're willing to use large integers.
Here's the basic idea:
1. List out all of the possible ways to choose K distinct integers from the range [0, N-1].
2. Throw a dart at the list, choosing one of those ways
Once yo... |
You can do it in **one** call to the *rand()* function, with a perfect uniform distribution, if you're willing to use large integers.
Here's the basic idea:
1. List out all of the possible ways to choose K distinct integers from the range [0, N-1].
2. Throw a dart at the list, choosing one of those ways
Once yo... |
You can do it in **one** call to the *rand()* function, with a perfect uniform distribution, if you're willing to use large integers.
Here's the basic idea:
1. List out all of the possible ways to choose K distinct integers from the range [0, N-1].
2. Throw a dart at the list, choosing one of those ways
Once yo... |
You can do it in **one** call to the *rand()* function, with a perfect uniform distribution, if you're willing to use large integers.
Here's the basic idea:
1. List out all of the possible ways to choose K distinct integers from the range [0, N-1].
2. Throw a dart at the list, choosing one of those ways
Once yo... |
You can do it in **one** call to the *rand()* function, with a perfect uniform distribution, if you're willing to use large integers.
Here's the basic idea:
1. List out all of the possible ways to choose K distinct integers from the range [0, N-1].
2. Throw a dart at the list, choosing one of those ways
Once yo... |
null |
The Bucheim-Walker algorithm is used for drawing trees (especially rooted trees). However, there are many real-world examples where DCGs would benefit from such an algorithm (e.g. family trees with intermarriage or incestual relationships, dependency graphs, etc.). Can the algorithm be modified to support DCGs? If so, ... |
Bucheim-Walker corollary for DCGs |
|trees|dag| |
The Bucheim-Walker algorithm is used for drawing trees. However, there are many real-world examples where DCGs would benefit from such an algorithm (e.g. family trees with intermarriage or incestual relationships, dependency graphs, etc.). Can the algorithm be modified to support DCGs? If so, how? Is there another algo... |
Consider a graph $G$ with $N$ nodes, with the distance of each node initially set to infinity (there is no start node). If there are no negative cycles in the graph, then after $N - 1$ iterations of Bellman-Ford, any additional iterations will not modify the distances (the distances are stable).
On the other hand, i... |
Does the Nth iteration of Bellman-Ford relax every edge reachable from a negative cycle? |
|graphs|shortest-path|weighted-graphs|dag| |
Instead of proving that the function returns false when the string is not of the specified form, let us use the contraposition.
Let $s = a_1…a_n$ be the string and assume that the function returns true. That means that $s$ is a substring of $a_2a_3…a_na_1a_2…a_{n-1}$. Since $s$ is of length $n$, that means that ther... |
null |
Using a 1 way 2 stack, and a 2 way 2 stack PDA, I want to check if the length of an input string is strictly a perfect square number. How can I do this in both approaches? |
1 way 2 stack and 2 way 2 stack Pushdown Accepters that accepts $L=\{a^{(n^2)} \mid n \geq 1\}$ |
null |
Given an integer n > 0, let x = A(n) be the value of the big Ackerman function. Is the sum of decimal digits of x greater then $4.5 \cdot \log_{10}(x)$? |
I am trying to find complexity for following algorithm. It is from "The Algorithm Design Manual" book.
```
for k = 1 to n:
x = k
while (x < n):
print ’*’
x = 2x
```
I simulated algorithm for some values. Each time inner loop operates on `n-k` value.
```
k=1
x=1
x=2
x=4
... |
Time complexity for logarithmic algorithm |
|time-complexity| |
Given an array with the size of $n$ of number. Our goal will be to analyze the expected running time of an algorithm that uses a hash table to find (if exists) a pair $(a,b)$ subject to $2<leq |a-b|<5$.
The answer is $O(n)$ but I have no idea to convince myself. Some thoughts that come to my mind are as follows: con... |
Find a pair $a,b$ with a range condition in Hash table |
|algorithms|hash| |
Given an array with the size of $n$ of number. Our goal will be to analyze the expected running time of an algorithm that uses a hash table to find (if exists) a pair $(a,b)$ subject to $2<|a-b|<5$.
The answer is $O(n)$ but I have no idea to convince myself. Some thoughts that come to my mind are as follows: conside... |
I am trying to find complexity for following algorithm. It is from "The Algorithm Design Manual" book.
```
for k = 1 to n:
x = k
while (x < n):
print ’*’
x = 2x
```
I simulated algorithm for some values. Each time inner loop operates on `n-k` value.
```
k=1
x=1
x=2
x=4
... |
Given an array with the size of $n$ of integer numbers. Our goal will be to analyze the expected running time of an algorithm that uses a hash table to find (if exists) a pair $(a,b)$ subject to $2<|a-b|<5$.
The answer is $O(n)$ but I have no idea to convince myself. Some thoughts that come to my mind are as follows... |
If all items in the hash table are integers, then the difference between a and b is 3 or 4. You need an iterator that iterates through all elements of the hash table in O(n) to find all possible values of b in random order; most hash table implements will provide this. Then for each be you check whether b-3 or b-4 is i... |
You need to add log (n / k), not log (n - k).
To examine this closer: For values n/2 <= k <= n you have only one iteration of the inner loop. For values n/4 <= k < n/2 you have two iterations. For values n/8 <= k < n/4 you have three iterations of the inner loop.
So the total number of iterations of the inner l... |
null |
$\sum\limits_{k=1}^{n}\log \frac{n}{k} = \sum\limits_{k=1}^{n}\log n-\sum\limits_{k=1}^{n}\log k = \log n^n - \log n! = n \log n - (n \log n - n) = O(n)$ |
null |
Solving $N$-player general sum matrix games is known to be PPAD-complete, and even for two players algorithms such as Lemke-Howson can take exponential time in the worst case. On the other hand, verifying that a solution is indeed a Nash equilibrium can be done in polynomial time.
Are there standard examples/benchma... |
Examples of challenging general-sum matrix games |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.