instruction
stringlengths
0
29.8k
⌀
I am stuck at the following exercise: > Consider a directed graph $G = (V, A)$ with start vertex $s ∈ V$, target vertex $t \in V$ and weights $w_{ij} \in \mathbb{R}$ for each arc $(i, j)\in A$. For any $i \in V$ let further be $\pi_i \in \mathbb{R}$ be the so-called **potential** of $i$. The potential difference $\t...
D.E. Knuth, in his infamous The Art of Computer Programming, section 1.2.2, presents the following algorithm to efficiently calculate logarithms basing on method used by Henry Briggs: > Suppose that we have a binary computer and a number $x$, $1\leqslant x < 2$. Show that the following algorithm, which uses only shi...
How to calculate error bounds for the function behind the following algorithm?
|algorithm-analysis|error-estimation|
Recently i studied three theorems which says about Hamiltonian graph, they are as follows, 1) Dirac's Theorem: Let G be some simple graph of order n >= 3, for all vertices of the graph G, its degree >= n/2 then we say given simple graph is actually an Hamiltonian graph. 2) Ore's Theorem: Let G be a simple gra...
Hamiltonian Graph Way
|graphs|hamiltonian-circuit|
In the following algorithm $A[1..n]$ denotes an array $A$ of size $n$, of $n$ distinct integers. Func1() and Func2() are functions that run in $\mathcal O(\log n)$ and $\mathcal O(n)$ time, respectively. Foo(A[1..n]) if n == 1: return while (True) { Func1() ...
Consider a graph $G$ that is a single cycle of length $\geqslant 5$. Then it should be clear that none of the properties is true, while $G$ is hamiltonian.
null
I am wondering if anyone knows if there are any NP-complete problems that are also known to be in IP (interactive polynomial time). I know problems like Graph Isomorphism are in IP, but such problems are not known to be NP-complete. Moreover, if there were or were not an NP-complete problem in IP, what would be th...
Are there any NP-complete problems that are also in IP?
|complexity-theory|np-complete|interactive-proof-systems|
It is a well known fact, the throughput of a given compute pipeline (say, CPU instruction pipeline) is determined by its "slow" segment. All the resources I've seen so far, demonstrates this fact via describing a **concrete** pipeline with 2-3 stages. I'd love to see, more-or-less, some formal proof, the above ho...
Formal proof for in-balanced pipeline throughput
|computer-architecture|cpu-pipelines|
The wikipedia article for [#P][1] states that if we have a polynomial-time algorithm for a #P-complete problem, P = NP is true. As #2SAT is #P-complete, this would mean that providing a polynomial-time algorithm for #2SAT implies P = NP. But why exactly is that? Which NP-complete problems can be reduced to #2SAT?...
Why solving #2SAT in polynomial time implies P = NP?
|complexity-theory|satisfiability|p-vs-np|counting|
The wikipedia article for [#P][1] states that if we have a polynomial-time algorithm for a #P-complete problem, P = NP is true. As #2SAT is #P-complete, this would mean that providing a polynomial-time algorithm for #2SAT implies P = NP. But why exactly is that? It means that there is at least one NP-complete pro...
[*The Complexity of Enumeration and Reliability Problems*](https://epubs.siam.org/doi/epdf/10.1137/0208032) by Leslie G. Valiant gives a series of reductions to prove that $\sharp\texttt{3SAT}\leqslant \sharp\texttt{2SAT}$. Since there is a trivial reduction from $\texttt{3SAT}$ to $\sharp\texttt{3SAT}$, you have the w...
$$ IP = PSPACE $$ According to [wikipedia](https://en.wikipedia.org/wiki/IP_(complexity)). Thus $NP \subseteq IP$ and all NP-complete problems are in $IP$.
In a [2015 Quanta article][1] talking about a breakthrough in the graph isomorphism problem, it was mentioned that graph isomorphism has a unique property where we have an interactive proof protocol for it. That is a prover can convince a verifier that two graphs are not isomorphic in polynomial time. That is, for the...
Are there any known interactive proof protocols for NP-complete problems?
|complexity-theory|np-complete|co-np|interactive-proof-systems|
In a [2015 Quanta article][1] talking about a breakthrough in the graph isomorphism problem, it was mentioned that graph isomorphism has a unique property where we have an interactive proof protocol for it. That is a prover can convince a verifier that two graphs are not isomorphic in polynomial time. That is, for the...
null
That article is talking about [Arthur-Merlin protocols](https://en.wikipedia.org/wiki/Arthur%E2%80%93Merlin_protocol), which are a certain type of interactive protocol, with additional restrictions. IP = PSPACE doesn't apply, because not all interactive protocols are Arthur-Merlin protocols. It is known that graph ...
This is formalized in [Amdahl's law](https://en.wikipedia.org/wiki/Amdahl%27s_law), which provides a quantitative version of that claim.
null
I will assume that the importance relation is [transitive](https://en.wikipedia.org/wiki/Transitive_relation), and in fact, forms a [partial order](https://en.wikipedia.org/wiki/Partially_ordered_set). If the algorithm is not free to choose which comparisons are done, but that was chosen by someone else and the algo...
I want to sort the list of parameters (p1, p2, p3, p4, ..., pn) according to their importance. All parameters have to be compared with each other at best once, but not less than once. The person will be asked to select the winner of the comparison, so for every comparison, there is only 1 winner. The workflow sh...
null
D.E. Knuth, in his infamous The Art of Computer Programming, section 1.2.2, presents the following algorithm to efficiently calculate logarithms based on the method used by Henry Briggs: > Suppose that we have a binary computer and a number $x$, $1\leqslant x < 2$. Show that the following algorithm, which uses only ...
null
null
null
null
**Input** There are three chairs (1,2,3) in the same row. We need to find a seat for three guests (a,b,c). **Constraints** *The first guest does not want to be seated next to the third one (neither left nor right). *The first guest does not want to be placed on the leftmost chair. *The second guest does n...
How to get the formal model using propositional logic
|satisfiability|propositional-logic|
**Input** There are three chairs (1,2,3) in the same row. We need to find a seat for three guests (a,b,c). **Constraints** - The first guest does not want to be seated next to the third one (neither left nor right). - The first guest does not want to be placed on the leftmost chair. - The second guest doe...
**Input** There are three chairs (1,2,3) in the same row. We need to find a seat for three guests (a,b,c). **Constraints** - The first guest does not want to be seated next to the third one (neither left nor right). - The first guest does not want to be placed on the leftmost chair. - The second guest d...
Consider the max-flow problem with a set of additional constraints, each in the following form: the flow on edge $e$ must equal the flow on edge $e'$. My question is how to modify existng max-flow algo to solve this variant.
Max-flow problem with additional constraint
|algorithms|optimization|combinatorics|network-flow|
bool isPrime(int n) const { if(n<2)return false; if(n==2)return true; if(n%2==0)return false; for(int i=3;(i*i)<=n;i++){ if(n%i==0)return false; } return true; } this worst case procedure should produce an O (sqrt (N)) which would be t...
search for the next prime number more efficiently?
|time-complexity|algorithm-analysis|runtime-analysis|big-o-notation|primes|
bool isPrime(int n) const { if(n<2)return false; if(n==2)return true; if(n%2==0)return false; for(int i=3;(i*i)<=n;i++){ if(n%i==0)return false; } return true; } this worst case procedure should produce an O (sqrt (N)) which would be t...
One way to solve the max-flow problem is that of considering the its linear programming formulation and using any algorithm to solve linear-programs. Given a directed graph $G=(V,E)$, a source $s \in V$ with no incoming edges, a sink $t \in V$ with no outgoing edges, and a non-negative capacity $c_e$ for each edge...
If this is going to be called a small number of times, efficiency doesn't really matter. If it's going to be called many times, then `isPrime()` should cache a list of already discovered primes (or an array of booleans indexed by the number to be tested) and run the loop only if *n* is larger than the largest in the...
null
null
null
For this problem, the simplest approach is to try all $3^3=27$ cases by hand. If you must use a SAT solver, introduce boolean variables to represent the solution. A natural approach is to let $x_{i,j}$ be true if the $i$th guest sits in the $j$th chair. Now you should be able to take it from here and translate eac...
Why is it possible that this word can have 4 errors but not 2?
Consider a Hamming(7, 4) code and the word 1111111 received at the output of a noisy binary channel
|error-correcting-codes|hamming-code|
null
I am reading a proof of correctness for the MergeSort Algorithm. This the code for the MergeSort and the Merge function: ![MergeSort code][1] The correctness of the MergeSort function is easy to prove, since the two `MergeSort` recursive calls decrease the size of the problem by a half, which guarantees the conve...
MergeSort's merge function loop invariant
|sorting|formal-methods|software-verification|loop-invariants|automated-theorem-proving|
|algorithm-analysis|formal-methods|software-verification|loop-invariants|automated-theorem-proving|
The message 1111111 cannot have 2 errors because 1111111 is a valid codeword and the minimum Hamming distance between any two distinct codewords of $H(7,4)$ is $3$. To see that it can have $4$ errors, notice that 0010110 is a valid codeword.
If we have the natural numbers defined as: [![enter image description here][1]][1] Plus the following: $pred \space \_\_<\_\_ \space: Nat \times Nat$ $\forall i,j:Nat$ - $0<suc(j)$ - $\neg(i<0)$ - $suc(i) < suc(j) \Longleftrightarrow i<j$ How to prove $0<i => 0 < i + j$ by induction? For the ...
0<i => 0 < i + j proof?
|induction|formal-methods|software-verification|
null
Let F be a function defined for all nonnegative integers by the following recursive definition. F(0) = 0, F(1)= 1 F(n + 2) = 2F(n) + F(n +1), n>0 Compute the first six values of F; that is, write the values of F(n) for n = 0,1,2,3,4,5
Let F be a function defined for all nonnegative integers by the following recursive definition
|logic|recursion|sets|counting|
There is no need for an induction here. - if $j = 0$ then $0<i \Rightarrow i - j = i + 0 = i>0$; - otherwise, $j = suc(j')$ and $0 < i \Rightarrow i+j = i+suc(j') = suc(i + j') > 0$.
You need a full set of axioms. For this, you can use the axioms for 1. a monoid: *associativity* $x(yz) = (xy)z$ and *identity* $x1 = x = 1x$; 2. a partial ordering possessing finite least upper bounds: defining $0 = ⋁∅$ and $a + b = ⋁\{a,b\}$: they are another instance of monoid axioms $x + (y + z) = (x + y) + z...
You need a full set of axioms. For this, you can use the axioms for 1. a monoid: *associativity* $x(yz) = (xy)z$ and *identity* $x1 = x = 1x$; 2. a partial ordering possessing least upper bounds $⋁F$ of finite subsets $F$: defining $0 = ⋁∅$ and $a + b = ⋁\{a,b\}$: an equivalent set of identities is captured by an...
This problem can be solved by minimum spanning tree (in time $O(n\log n + m)$). Let $S$ be the set of sources and $T$ the set of destinations. Start by adding a vertex $u$ and make it adjacent to all destination vertices (with zero weight). Compute a minimum spanning tree of the resulting graph. You can choose the ...
Complement means relative complement $Σ^* - L$. You already have closure under set subtraction and, in fact, also intersection and even interleave. So, the real question is how to do set-subtraction. You can evaluate it algebraically, but you get a system that amounts to the description of a deterministic automaton....
What you are after is called an "incremental sieve" in the literature. The [sieve of Bengalloun][1] does a little better than what you have requested: it only requires $O(p_i - p_{i-1})$ time, and can be sped up by a $\log\log p_i$ factor. The article is paywalled, but there is a nice brief description of the algorithm...
That's actually just a bit of clever programming; I wouldn't even call it "computer science". Create a data structure that you call a sieve. For example, using one byte for the numbers from 30k to 30k + 29 to indicate which of 30k+1, 30k+7, 30k+11, 30k+13, 30k+17, 30k+19, 30k+23 and 30k+29 are primes. At any point in t...
Just one part of the answer: You calculate a sequence and look for cycles. There are two well-known algorithms for cycle detections. One calculates $x_{2k}$ and $x_k$ in parallel which will found cycles, the other tries to detect cycles of length 2, then length 4, then length 8, then length 16, by calculating the value...
Just one part of the answer: You calculate a sequence and look for cycles. There are two well-known algorithms for cycle detections. One calculates $x_{2k}$ and $x_k$ in parallel which will find cycles, the other tries to detect cycles of length 2, then length 4, then length 8, then length 16, by calculating the values...
This problem can be solved by minimum spanning tree (in time $O(n\log n + m)$). Let $S$ be the set of sources and $T$ the set of destinations. Start by adding a vertex $u$ and make it adjacent to all destination vertices (with zero weight). Compute a minimum spanning tree of the resulting graph. You can choose the ...
Just one part of the answer: You calculate a sequence and look for cycles. There are two well-known algorithms for cycle detections. One calculates $x_{2k}$ and $x_k$ in parallel which will find cycles, the other tries to detect cycles of length 2, then length 4, then length 8, then length 16, by calculating the values...
Just one part of the answer: You calculate a sequence and look for cycles. There are two well-known algorithms for cycle detections, Brent's and Floyd's. One calculates $x_{2k}$ and $x_k$ in parallel which will find cycles, the other tries to detect cycles of length ≤ 2, then length ≤ 4, then length ≤ 8, then length ≤ ...
null
There is no need for an induction here. - if $j = 0$ then $0<i \Rightarrow i + j = i + 0 = i>0$; - otherwise, $j = suc(j')$ and $0 < i \Rightarrow i+j = i+suc(j') = suc(i + j') > 0$.
null
I am learning about context free languages. I understand how {a^nb^nc^n|n>0} can be shown to be not context free using the pumping lemma for CFL's. Intuitively however it seems that a pushdown automata to recognize {a^nb^nc^n|n>0} can be constructed. This PDA would initially push single a's into its stack wheneve...
Push Down Automata
|context-free|pushdown-automata|
Assuming a contiguous array implementation of a binary min heap with `n` elements, is it possible to remove the k-smallest elements in a faster time than $O(k \log n)$, as can be done via iteratively removing the minimum of the heap $k$ times?
Removing k-smallest elements in a binary min-heap
|algorithms|heaps|
No, it is not possible: since it is possible to build a min-heap with $n$ elements in [$\mathcal{O}(n)$ time](https://stackoverflow.com/questions/9755721/how-can-building-a-heap-be-on-time-complexity), being able to remove $k$ elements in $o(k\log n)$ would result in a sorting algorithm in $o(n\log n)$ when removing $n...
Because there is no control on the number of $b$'s, such a pushdown automaton would recognize $\{a^nb^mc^n\mid n, m> 0\}$ which is indeed context-free.
No, it is not possible: since it is possible to build a min-heap with $n$ elements in [$\mathcal{O}(n)$ time](https://stackoverflow.com/questions/9755721/how-can-building-a-heap-be-on-time-complexity), being able to remove $k$ elements in $o(k\log n)$ would result in a sorting algorithm in $o(n\log n)$ when removing $n...
I am fitting different 2D geometric transformations by least-squares. For instance quadratic, $$\begin{cases}a'x^2+b'xy+c'y^2+d'x+e'y+f'=X\\a''x^2+b''xy+c''y^2+d''x+e''y+f''=Y\end{cases}$$ which is linear in the unknowns $a',b',\cdots f''$. I also solve homographic transformations $$\begin{cases}\dfrac{a...
Least squares fit of a rational function
|computational-geometry|modelling|
I am fitting different 2D geometric transformations by least-squares. For instance quadratic, $$\begin{cases}a'x^2+b'xy+c'y^2+d'x+e'y+f'=X\\a''x^2+b''xy+c''y^2+d''x+e''y+f''=Y\end{cases}$$ which is linear in the unknowns $a',b',\cdots f''$. I also solve homographic transformations $$\begin{cases}\dfrac{a...