instruction stringlengths 0 29.8k ⌀ |
|---|
The first loop has y iterations, each iteration takes constant time (O(1)), so alltogether we have O(y). The second loop has ld(y) iterations of constant time, giving a complexity of O(ld(y)). Both loops together we have: O(y + ld(y)) = O(y) because y dominates ld(y). |
I have two pieces of code in a function which I'm trying to calculate the running time for:
for (int x = 0; x < y; x++){
total += total;
total += x;
}
and:
while (y > 0){
total -= y;
y = y/2;
}
combining those two pieces of code, what is the run time of that fun... |
Calculating Running Time |
|untagged| |
|time-complexity|imperative-programming|loops| |
I have two pieces of code in a function which I'm trying to calculate the asymptotic running time for:
for (int x = 0; x < y; x++) {
total += total;
total += x;
}
and:
while (y > 0) {
total -= y;
y = y/2;
}
Combining those two pieces of code, wha... |
Asymptotic time complexity of a two-loop program |
Is the complement of the $HAMPATH$ problem known to be in $NP$ ? I could not find explanations saying that it is, but then neither were there any claims saying that it is **not** in $NP$. |
Complement of $HAMPATH$ |
|complexity-theory| |
I have some difficulties performing the worst case analysis on this algorithm.
The outermost loop is executed $2N$ times.
The while loop, in the worst case, will increase by $2$ each time, so it performs $i/2$ basic operations ($*2$ because double call)
for (i=1; i<=2*N; i++) {
j = 0;
... |
Computational complexity analysis |
|algorithms| |
Are there any superpolynomial time set $\mathsf{SP}$ in between $\mathsf{P}$ and $\mathsf{EXPTIME}$ such that the problem $\mathsf{SP}=\mathsf{NSP}$ has a known answer?
**UPDATE**: It must be defined by time and strictly between $\mathsf{P}$ and $\mathsf{EXPTIME}$. I was wondering, what if Cobham's thesis is wrong a... |
Superpolynomial time set such that SP=NSP is known? |
|complexity-theory|nondeterminism| |
null |
Take any time complexity class and its corresponding nondeterministic counterpart: $\mathsf{DTime(F)}$ and $\mathsf{NTime}(F)$ where $F$ is a family of nice functions containing polynomials and bounded by exponential functions. You are asking if we know these two classes are equal. We don't know!
The question about ... |
Take any time complexity class and its corresponding nondeterministic counterpart: $\mathsf{DTime(F)}$ and $\mathsf{NTime}(F)$ where $F$ is a family of nice functions containing polynomials and bounded by exponential functions. You are asking if we know these two classes are equal. We don't know!
Take $SAT$ as an ex... |
1. Your solution is valid and follows definition of *d*-ary heap. But as you pointed out your notation is a bit sophisticated.
You might use those two following functions to retrieve parent of *i*-th element and *j*-th child of *i*-th element.
$\text{d-ary-parent}({\it i}) \\
\ \ \ \ {\bf return}\ \lfloor (i... |
I got confused while solving the following problem...
###Question##
A *d*-ary heap is like a binary heap, but(with one possible exception) non-leaf nodes have *d* children instead of 2 children.
1. How would you represent a *d*-ary heap in an array?
2. What is the height of a *d*-ary heap of *n* elements in... |
null |
I got confused while solving the following problem (questions 1–3).
###Question##
> A *d*-ary heap is like a binary heap, but(with one possible exception) non-leaf nodes have *d* children instead of 2 children.
> 1. How would you represent a *d*-ary heap in an array?
> 2. What is the height of a *d*-ary hea... |
I am not talking about NP-indeterminate class because those problems have to be shown to not exist either in P or NP-complete class and existence of such problems proves P!=NP. I am interested to know if we are half-way there i.e. problems that have been proven to be not NP-complete but are in NP but we don't know if t... |
Are there are problems in NP that have been shown to be not NP-complete but it is still not known if they are in P or not? |
|untagged| |
|algorithms|time-complexity|imperative-programming|loops| |
The HAMPATH complement ("G does not contain an Hamiltonian path from s to t") is in [co-NP][1]
The question if it is in NP is open.
But HAMPATH is NP-complete, so if its complement falls is in $\mathsf{NP}$ then $\mathsf{NP} = \mathsf{co\mbox{-}NP}$
[1]: http://en.wikipedia.org/wiki/Co-NP |
|complexity-theory| |
null |
If $S_1,S_2$ are set of strings, then $S_1S_2 = \{s_1s_2|s_1\in S_1, s_2\in S_2\}$. $S^0=\{\epsilon\}$, $\epsilon$ is the empty string. $S^n = S^{n-1}S$.
Two related problems about represent string as concatenation of other strings.
1. Given a finite set $S$ of strings, how to decide if there exist a string can... |
|algorithms|formal-languages|strings| |
The HAMPATH complement ("G does not contain an Hamiltonian path from s to t") is in [co-NP][1]
The question if it is in NP is open.
But HAMPATH is NP-complete, so if its complement is in $\mathsf{NP}$ then $\mathsf{NP} = \mathsf{co\mbox{-}NP}$
[1]: http://en.wikipedia.org/wiki/Co-NP |
|algorithms|time-complexity|algorithm-analysis|runtime-analysis|loops| |
Any problem that is provably not $\mathsf{NP}$ complete (w.r.t. polynomial time reductions) would mean that the class of problems reducible to it are distinct from $\mathsf{NP}$. In other words if you show some problem is in $\mathsf{NP}$ but is not $\mathsf{NP}$ complete would imply that $\mathsf{P}$ is not equal to $... |
Is the complement of the [Hamiltonian Path problem](http://en.wikipedia.org/wiki/Hamiltonian_path) known to be in $\mathsf{NP}$? I could not find explanations saying that it is, but then neither were there any claims saying that it is **not** in $\mathsf{NP}$. |
Complement of HAMPATH |
|complexity-theory|decision-problem| |
Any problem that is provably not $\mathsf{NP}$ complete (w.r.t. polynomial time reductions) would mean that the class of problems reducible to it are distinct from $\mathsf{NP}$. In other words if you show some problem is in $\mathsf{NP}$ but is not $\mathsf{NP}$ complete would imply that $\mathsf{P}$ is not equal to $... |
The HAMPATH complement ("G does not contain an Hamiltonian path from s to t") is in [co-NP][1]; to be more precise it is [co-NP complete][2] (it is easy to prove that $L$ is NP-complete if and only if its complement $\bar{L}$ is co-NP-complete).
The question if it is in NP is open.
But since HAMPATH is NP-comple... |
I've been trying to implement Brzozowski's algorithm but I've just discovered that it creates suboptimal automata for a certain class of inputs, having one more state than what is really needed in the result. I can show it on a trivial automaton:
a b a b a b a b ... |
Problem with implementing Brzozowski's algorithm |
|automata| |
I've been trying to implement Brzozowski's algorithm but I've just discovered that it creates suboptimal automata for a certain class of inputs, having one more state than what is really needed in the result. I can show it on a trivial automaton:
a b a b a b a b ... |
I'm trying to figure out why NOT and CNOT gates are not sufficient to create all bijective functions in classical ccircuits. I have been struggling on this for hours, and just can't make sense of it.
I feel it has something to do with the Toffoli gate, as it contains an (implicit) AND operation, and I feel that's wh... |
Universality of NOT and CONT |
|logic| |
Let's say I found a 2-approximation algorithm for a certain problem and I want to show that the analysis is tight.
Do I now need to come up with an example of generic size $n$ or does it suffice to show that I have an example of size $10$ for which the algorithm yields $2OPT$? |
Providing Tight Example in Approximation Algorithm Analysis |
|algorithms|approximation| |
Suppose we want to compute $x \land y$ from $x,y,0,1$ using the operations NOT and CNOT (=XOR). Prove by induction that any such expression is equal to one of the following forms:
$$ 0,1,x,y,\lnot x, \lnot y, x\oplus y, \lnot(x\oplus y). $$
It is more helpful to write it in the form $ \alpha \oplus (\beta \land x) \o... |
That depends on your definition of approximation ratio. Normally the approximation ratio is defined as the worst ratio between optimal solution and the one produced by your algorithm. If this is the case, all you need to show that the ratio is tight is come up with one bad example.
Sometimes, however, you prove some... |
Does there exist a procedure that determines if a polytime machine prints a certain string, and does so in less time than the machine itself takes to run?
Define a machine $a$ that analyzes another machine $b$, input $i$, and string $r$:
$a(b,i,r) = b(i) \text{ prints } r$ &nbs... |
I have the following problem:
Define the keyed function F as follows: On input k ∈ {0, 1}$^n$
and x ∈ {0, 1}$^n$ , Fk(x) = k ⊕ x.Rigorously prove that F is not a pseudorandom function.
How do I approach a proof against pseudorandomness for a keyed function? I don't know where to start with this one.
|
Rigorous proof against pseudo random function |
|cryptography| |
It's always the same answer - **go back to the definitions**.
the definition of PRF, defines a *family* of functions $\{f_k\}$. The key $k$ just selects one specific function out of this big family.
Next, the definition requires that any algorithm $A$ will not be able to distinguish a member of the that family, f... |
|logic|quantum-computing|circuits| |
I'm trying to figure out why NOT and CNOT gates are not sufficient to create all bijective functions in classical ccircuits. I have been struggling on this for hours, and just can't make sense of it.
I feel it has something to do with the Toffoli gate, as it contains an (implicit) AND operation, and I feel that's wh... |
Edit: This is a proof for the non-quantum version.
Suppose we want to compute $x \land y$ from $x,y,0,1$ using the operations NOT and CNOT (=XOR). Prove by induction that any such expression is equal to one of the following forms:
$$ 0,1,x,y,\lnot x, \lnot y, x\oplus y, \lnot(x\oplus y). $$
It is more helpful to w... |
If $S_1,S_2$ are set of strings, then $S_1S_2 = \{s_1s_2|s_1\in S_1, s_2\in S_2\}$. $S^0=\{\epsilon\}$, $\epsilon$ is the empty string. $S^n = S^{n-1}S$.
Two related problems about represent string as concatenation of other strings.
1. Given a finite set $S$ of strings, how to decide if there exist a string can... |
|logic|circuits| |
First, consider this simple problem --- design a data structure of *comparable* elements that behaves just like a stack, but can also return its min value in $O(1)$ time. This is easy by maintaining a second stack of min values. Now, consider the same problem, where the stack is replaced by a queue. This seems impossib... |
Lower bounds: queues that return their min elements in $O(1)$ time |
|data-structures|lower-bounds| |
The radon transform is used to take 2d projections of an object and create a 3d representation.
It seems like it would be possible to such such a transform in 3d graphics in games(although possibly too slow to be practical).
For example, a very simple way to display an object is to use a 3d rectangle and textur... |
Radon transform for advanced 3d graphics and games? |
|graphics| |
Automatic parallelization in the most general terms is extracting a dependency graph from the execution sequence of the program and executing distinct paths in this graph in parallel with synchronization introduced at the nodes of the graph where the paths merge.
Our ability to extract the dependency information var... |
null |
|algorithms|automata|finite-automata| |
|algorithms|computational-geometry|efficiency|graphics| |
The [Radon transform](https://en.wikipedia.org/wiki/Radon_transform) is used to take 2d projections of an object and create a 3d representation.
It seems like it would be possible to apply such a transform in 3d graphics in games (although possibly too slow to be practical).
For example, a very simple way to disp... |
|algorithms|proof-techniques|approximation| |
Let $f(N)$ denote the number of `function` calls within the loop.
Substituting $N+1$ instead of $N$ into the code you can observe that the first $2N$ iterations of the outer loop remain exactly the same and the last two iterations add up to $N+1$ and $N+2$ iterations of the inner loop each. Since each iteration of t... |
For a modern CPU there is no exact MIPS rating since it depends on the specific instruction stream, power saving mode, and other factors. As a reference number you may look at the [BogoMIPS](http://en.wikipedia.org/wiki/BogoMips) rating that is calculated by the Linux kernel.
A desktop CPU core at 3GHz can process a... |
Let $f(N)$ denote the number of `function` calls within the loop.
Substituting $N+1$ instead of $N$ into the code you can observe that the first $2N$ iterations of the outer loop remain exactly the same and the last two iterations add up to $N+1$ and $N+2$ iterations of the inner loop each. Since each iteration of t... |
When returning the min element, I assume you also want to remove it from the data structure? Otherwise it's trivial to just always keep track of the least element when you alter the data structures via any of the other operations.
I'm not entirely sure how much cheating you allow, but you could keep two additional ... |
null |
null |
First, consider this simple problem --- design a data structure of *comparable* elements that behaves just like a stack (in particular, push(), pop() and top() take constant time), but can also return its min value in $O(1)$ time, without removing it from the stack. This is easy by maintaining a second stack of min val... |
I am having issue with designing contex free grammar for the following language:
$L = \{0^n 1^m \, | \, 2n \leq m \leq 3n \}$
I can design for the individual cases i.e. for $m \geq 2n$ and $m \leq 3n$ but don't know how should i combine both. Or is it a different approach altogether?
|
Designing context free grammar for a language with range restriction on repetition of alphabets |
|context-free| |
It has been a while, since I have done context-free grammars, but I think this should be the answer:
$A->0A11|0A111|-$
$-$ is the empty symbol, since I am assuming that empty string is in $L$.
The idea behind is, that you are working your way from outside. Since you need at least 2 times more of $1$'s, than yo... |
1. Your solution is valid and follows definition of *d*-ary heap. But as you pointed out your notation is a bit sophisticated.
You might use those two following functions to retrieve parent of *i*-th element and *j*-th child of *i*-th element.
$\text{d-ary-parent}({\it i}) \\
\ \ \ \ {\bf return}\ \lfloor (i... |
null |
It has been a while, since I have done context-free grammars, but I think this should be the answer:
$A->0A11|0A111|\epsilon$
I am assuming that empty string is in $L$.
The idea behind is, that you are working your way from outside. Since you need at least 2 times more of $1$'s, than you need $0$'s, you need t... |
null |
It has been a while, since I have done context-free grammars, but I think this should be the answer:
$\qquad \displaystyle A \to 0A11 \mid 0A111 \mid \varepsilon$
I am assuming that empty string is in $L$.
The idea behind is, that you are working your way from outside. Since you need at least 2 times more of $... |
This is an excellent question!
The reverting step in Brzozowski's Algorithm does not introduce a new virtual starting state that leads to the old accepting states via $\varepsilon$-transitions. Instead it allows multiple starting states, which is no big problem, if you construct the product-automaton anyway right af... |
Below proof is wrong; we need $c<1$ which can only work if $d_1 \leq 2d_2$ -- but there is no reason to believe that this should always be true.
---
The trouble is that you don't *know* $f$; it could be any one of the functions in $\Theta(n^2)$ resp. $\Omega(n^2)$.
So let's unfold the classes! In case one, whi... |
If your algorithm achieves a 1.5 approximation on all but a finitely set $S$ of instances, on which your algorithm achieves a 2-approximation, then you could "improve" your algorithm by "hardwiring" the optimal solutions for the instances in $S$ into your algorithm. In short, for theoretical purposes, an algorithm that... |
If your algorithm achieves a 1.5 approximation on all but a finite set $S$ of instances, on which your algorithm achieves a 2-approximation, then you could "improve" your algorithm by "hardwiring" the optimal solutions for the instances in $S$ into your algorithm. In short, for theoretical purposes, an algorithm that s... |
I'm trying to figure out why NOT and CNOT gates are not sufficient to create all bijective functions in classical circuits. I have been struggling on this for hours, and just can't make sense of it.
I feel it has something to do with the Toffoli gate, as it contains an (implicit) AND operation, and I feel that's wha... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.