instruction
stringlengths
0
29.8k
⌀
Consider the notion of optimal implementation as follows. Suppose we have some algorithm $A$ whose execution for some problem of size $N$ requires $T(N)$ operations (e.g. arithmetic operations). A library optimally implements this algorithm when it executes the algorithm for a problem of size $N$ on a CPU (or some othe...
Consider the notion of optimal implementation as follows. Suppose we have some algorithm $A$ whose execution for some problem of size $N$ requires $T(N)$ operations (e.g. arithmetic operations). A library optimally implements this algorithm when it executes a routine for implementing the algorithm for a problem of size...
Consider the notion of optimal implementation as follows. Suppose we have some algorithm $A$ whose execution for some problem of size $N$ requires $T(N)$ operations (e.g. arithmetic operations). A library optimally implements this algorithm when it executes a routine for implementing the algorithm for a problem of size...
null
My algorithm takes a Java program as an input, modifies it to eliminate the usage of static attributes, and returns a new modified Java program. What would be the soundness and completeness of this algorithm? Let's assume, the input program has $S$ static attributes and $N$ non-static ones. Let's also assume that the o...
How to define soundness and completeness of a transformation algorithm?
|algorithms|
My algorithm takes a Java program as an input, modifies it to _eliminate_ the usage of static attributes, and returns a new modified Java program. What would be the soundness and completeness of this algorithm? Let's assume, the input program has $S$ static attributes and $N$ non-static ones. Let's also assume that the...
My algorithm takes a Java program as an input, modifies it to _eliminate_ [static](https://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html) attributes, and returns a new modified Java program without such attributes. What would be the soundness and completeness of this algorithm? Let's assume, the input prog...
[Federal Information Processing Standard 186-4 appendix C.4][1] gives (without reference) an algorithm intended to test if a positive integer $C$ (which can be thousands bits) is a square: 1. Set $n$, such that $2^n>C\ge2^{(n-1)}$. 2. $m=\lceil n/2\rceil$. 3. $i=0$. 4. Select $X_0$, such that $2^m>X_0\ge2^{(m-1)}$....
As far as I understand your question, there is no such concept. The "minimum" number of operations to achieve a given task is completely dependent on the instruction set of the particular CPU. And if you don't limit yourself to existing CPUs, many option remain for custom designs (FPGAs, ASICs...), where the minimum is...
What you are looking for may be *encoding* instead of *hash*. This can be done using some steps, however, the corresponding integers may be big. - given $a$, $b$ two integers, denote $\langle a, b\rangle$ an encoding of the couple $(a, b)$. The expression $\langle a, b\rangle = \dfrac{(a+b)(a+b+1)}2 + a + 1$ is ...
Use the five-stage pipeline with forwarding unit. add $t1, $t2, $t3 sw $t1, 0($t4) I know the data hazard can be solved by forwarding, but i'm not sure if my explanation is correct: "When SW arrives EXE stage(add in MEM stage), the forwarding unit in EXE stage detects $t1 has hazard. Therefore, $t1...
Data hazard in MIPS: SW after ADD
|cpu-pipelines|mips|
Use the five-stage pipeline with forwarding unit. add $t1, $t2, $t3 sw $t1, 0($t4) I know the data hazard can be solved by forwarding, but i'm not sure if my explanation is correct: "When SW arrives EXE stage (add in MEM stage), the forwarding unit in EXE stage detects t1 has hazard. Therefore, t1 ...
Here's a thought, not tried, and not backed up by literature. But at least it's more computationally efficient than your current approach. If anyone has thoughts or references, please leave a comment. I'll assume that your chromosomes consist of binary genes, but an extension to real-valued genes might be possible. ...
Consider the notion of optimal implementation as follows. Suppose we have some algorithm $A$ whose execution for some problem of size $N$ requires $T(N)$ operations (e.g. arithmetic operations). A library optimally implements this algorithm when it executes a routine for implementing the algorithm for a problem of size...
As far as I understand your question, there is no such concept. The "minimum" number of operations to achieve a given task is completely dependent on the instruction set of the particular CPU. And if you don't limit yourself to existing CPUs, many options remain for custom designs (FPGAs, ASICs...), where the minimum i...
Hash codes will not be identical "if and only if the data is identical". There are more possible trees than possible hash codes, so there will be many trees with the same hash code. What you _need_ to achieve: Two trees that compare equal have the same hash code, and two trees with different hash codes don't compare eq...
What you are looking for may be *encoding* instead of *hash*. This can be done using some steps, however, the corresponding integers may be big. - given $a$, $b$ two integers, denote $\langle a, b\rangle$ an encoding of the couple $(a, b)$. The expression $\langle a, b\rangle = \dfrac{(a+b)(a+b+1)}2 + a + 1$ is ...
In Strassen's algorithm, we calculate the time complexity based on n being the number of rows of the square matrix. Why don't we take n to be the total number of entries in the matrices (so if we were multiplying two 2x2 matrices, we would have n = 8 for the four entries in each matrix)? Then, using the naïve method ...
In algorithms for matrix multiplication (eg Strassen), why do we say n is equal to the number of rows and not the number of elements in both matrices?
|algorithms|time-complexity|matrices|multiplication|
null
In the substitution method, if we find that, for instance, T(n) < d*n*lg(n) but only for some d that depends on n, then can we say that T(n) = o(nlg(n)) (little-oh) in some cases? For example, in this case: we may find that the condition T(n) <= d*n*lg(n) is only satisfied if d <= n or, conversely, n>=d. That would mea...
If we find that, e.g., T(n)<=d*n*lg(n) for some d that depends on n, is T(n)=o(nlgn)?
|time-complexity|runtime-analysis|
> Here, n = 8 and we are doing n = 8 multiplications and n/2 = 4 additions. So even a naïve multiplication algorithm would yield a time complexity of O(n). That is wrong. It might work for a small example like $n = 8$, but for bigger ones it doesn't. E.g. if you have two square matrices with a total of $n = 200$ ...
For n = 100, the naive algorithm takes 1,000,000 multiplications and almost as many additions. If we let n = number of rows / columns, then it takes $n^3$ multiplications and $n^3 - n^2$ additions. If we let $m = 2n^2$, that is the total number of elements in both matrices, then it is $m^{1.5} / 2^{1.5}$ multiplication...
You can take any matrix with N/2 < n < N rows and columns, pad it, and multiply it with Strassen's algorithm (or the naive algorithm for example), and then drop lots of zeroes that were created by the padding. But the execution time between N/2 and N rows only grows by a constant factor 7. Since we don't calculate the ...
null
null
null
Is there a hashing function $f$ that for each input $x$ computes $y$ such that $f(x \, || \, y) = y$? In other words, if we concatenate its output with the input, the result will not change. Furthermore, is there a simple construction for such functions? ## Example Let $x =$ `"hello"` and $f(x) =$ `"123"`. The...
Self referential hash function possible?
|algorithms|computability|hash|cryptography|fixed-point|
Is there a hashing function $f$ that for each input $x$ computes $y$ such that $f(x \, || \, y \, || \c x) = y$? In other words, if we concatenate its output with the input, the result will not change. Furthermore, is there a simple construction for such functions? ## Example Let $x =$ `"hello"` and $f(x) =$ `...
Is there a hashing function $f$ that for each input $x$ computes $y$ such that $f(x \, || \, y \, || \, x) = y$? In other words, if we concatenate its output with the input, the result will not change. Furthermore, is there a simple construction for such functions? ## Example Let $x =$ `"hello"` and $f(x) =$ `...
Is there a hashing function $f$ that for each input $x$ if $f(x) = y$, then $f(x \, || \, y) = y$? In other words, if we concatenate its output with the input, the result will not change. Furthermore, is there a simple construction for such functions? ## Example Let $x =$ `"hello"` and $f(x) =$ `"123"`. Then $...
Is there a hashing function $f$ that for each input $x$ if $f(x) = y$, then $f(x \, || \, y) = y$? In other words, if we concatenate its output with the input, the result will not change. Furthermore, is there a simple construction for such functions? ## Example Let $x =$ `"hello"` and $f(x) =$ `"123"`. Then $...
Yes. You can construct such a function. Let $g:\{0,1\}^* \to \{0,1\}^k$ be any hash function. We will define $f$ as follows. On input $x = x_1 \cdots x_n$, compute: - For $i := 1,2,3,\dots,n$, do: - If $i \ge k+1$ and $z_{i-k} = x_{i-k+1} \cdots x_i$, then set $z_i = x_{i-k+1} \cdots x_i$; otherwise, set $z...
As far as I understand your question, there is no such concept. The "minimum" number of operations to achieve a given task is completely dependent on the instruction set of the particular CPU. And if you don't limit yourself to existing CPUs, many options remain for custom designs (FPGAs, ASICs...), where the minimum i...
Yes, it is possible. Suppose $d=1/n$ and $T(n) = 0.5 \log n$. Then you'll find that $T(n) < d n \log n$, and it is also true that $T(n) = o(n \log n)$. In this case, it might be misleading to use a letter like $d$ for a function of $n$; people might expect you to write $d(n)$. Typically, letters like $c,d,\dots$ ...
You *would* be correct, however the question specifically states: > Assume registers can be written and read in the same cycle, during writeback This means that in cycle 5, 'W' and 'D' are allowed to occur simultaneously, and there must be some sort of implicit forwarding between the two. In light of these assum...
null
No Consider W the set of the functions that maps {0, 1}×{0, 1} to {0, 1}. For example, the AND gate (denoted by ^) and the XOR gate (denoted by ⊕) are elements of W. Now, for f ∈ W, define Val(f) in that way: Val(f) := f(0, 0) ⊕ f(0, 1) ⊕ f(1, 0) ⊕ f(1, 1) Its possible to prove that Val(¬f) = Val(f) and th...
null
null
Is there a well-known algorithm for modular multiplication of floating-point numbers? I would like to multiply some large angle in single precision (6-7 significant digits) and wrap it back to 360 degrees, without losing too many significant digits. float r = fmodf(a * b, 360); My current approach is to sp...
Floating-point modular multiplication algorithm
|algorithms|floating-point|modular-arithmetic|
null
Given a bipartite simple graph $G=(V,E)$, where $V=A\cup B$ and $A\cap B=\emptyset$, any edge in $E$ connects two vertices in $A$ and $B$, respectively. The maximum bipartite matching problem is to find the largest subset $E'\subseteq E$ such that no two edges in $E'$ share common vertices. We know that this can be add...
A variation of the maximum bipartite matching problem
|algorithms|graphs|network-flow|bipartite-matching|
null
From $$n=2^c\le N<2n=2^{c+1}$$ you draw $$n^{\alpha}\le N^\alpha<(2n)^{\alpha}=2^\alpha n.$$ As $2^\alpha$ is a constant, you can write $$N^\alpha=\Theta(n^\alpha).$$
Let $Y_v$ be the random variable that indicates whether vertex $v$ is added to the independence set. The probability that $v$ appears before all vertices that are incident to $v$ in a random ordering is $\frac1{\deg(v)+1}$, since all orderings are equally likely and all $\deg(v)+1$ vertices involved are symmetric to on...
Are two regularity properties on hypergraphs equivalent?
|algorithms|graphs|combinatorics|definitions|
On the internet, I am unable to find concrete definitions of these three types of file-systems. Can someone clearly explain the difference between these?
Difference between Distributed File System, Cluster File System and Parallel File System
|distributed-systems|parallel-computing|clustering|filesystems|
Short answer: because it's natural and convenient. Longer answer: The number of multiplications to multiply a matrix of size p,q with a matrix of size q,r is pqr with a naive algorithm, and something more complicated with a smarter algorithm. The number of multiplications to multiply two square matrices of size n,n ...
I have sequence of integers $a_1, a_2, .., a_n$, let $S_a = \sum_{i=1}^{N}{a_i}$, for any $k \in (0; 1)$ I need an algorthim to that maps every $a_i$ into another integer $b_i$ with 2 requirements: 1. $S_b = \sum_{i=1}^{N}{a_i}$ is as close as possible to $k \cdot S_a$, ideally $S_b = Round(k \cdot S_a)$ 2. $...
Sampling from bins with ratio preservation
|algorithms|integers|sampling|rounding|
Compute the prefix sum of the $a_i$, multiply all elements by $k$ and round. Now the desired integers are the pairwise differences of that sequence. E.g. $a=(3,6,2,7,9), k=0.8\to(3,9,11,18,27)\to(2,7,9,14,22)\to(2,5,2,5,8)$.
Compute the prefix sum of the $a_i$, multiply all elements by $k$ and round. Now the desired integers are the pairwise differences of that sequence. The first condition is always honored. E.g. $a=(3,6,2,7,9), k=0.8\to(3,9,11,18,27)\to(2,7,9,14,22)\to(2,5,2,5,8)$.
I have sequence of integers $a_1, a_2, .., a_n$, let $S_a = \sum_{i=1}^{N}{a_i}$, for any $k \in (0; 1)$ I need an algorthim to that maps every $a_i$ into another integer $b_i$ with 2 requirements: 1. $S_b = \sum_{i=1}^{N}{b_i}$ is as close as possible to $k \cdot S_a$, ideally $S_b = Round(k \cdot S_a)$ 2. $...
Given a bipartite simple graph $G=(V,E)$, where $V=A\cup B$ and $A\cap B=\emptyset$, any edge in $E$ connects two vertices in $A$ and $B$, respectively. The maximum bipartite matching problem is to find the largest subset $E'\subseteq E$ such that no two edges in $E'$ share common vertices. We know that this can be add...
For n = 100, the naive algorithm takes 1,000,000 multiplications and almost as many additions. If we let n = number of rows / columns, then it takes $n^3$ multiplications and $n^3 - n^2$ additions. If we let $m = 2n^2$, that is the total number of elements in both matrices, then it is $m^{1.5} / 2^{1.5}$ multiplication...
Short answer: because it's natural and convenient. Longer answer: The number of multiplications to multiply a matrix of size p,q with a matrix of size q,r is pqr with a naive algorithm, and something more complicated with a smarter algorithm. The number of multiplications to multiply two square matrices of size n,n ...
Use the five-stage pipeline with forwarding unit. add $t1, $t2, $t3 sw $t1, 0($t4) In the above code, is the data hazard of t1 fixed by forwarding the correct t1 value from MEM stage to EXE stage? Also, are there totally four forwarding paths, which are MEMtoEXE, WBtoEXE, MEMtoID, WBtoMEM, in pipeline...
Is there a well-known algorithm for modular multiplication of floating-point numbers? I would like to multiply some large angle in single precision (6-7 significant digits) and wrap it back to 360 degrees, without losing too many significant digits. float r = fmodf(a * b, 360); My current approach is to sp...
Your reasoning is wrong. In the first place, unless $d(n)$ is constant, $n\ge n_0=d$ does not hold. And even if that was the case, $dn\log(n)=o(n\log(n))$ would be incorrect (as is the statement "for every $d$"). Clearly $$d(n)n\log(n)=o(n\log(n))$$ requires $$d(n)=o(1).$$
Your reasoning is wrong. In the first place, unless $d(n)$ is constant, $n\ge n_0=d$ does not hold. And even if that was the case, $dn\log(n)=o(n\log(n))$ would be incorrect (as is the statement "for every $d$"). Clearly $$d(n)n\log(n)=o(n\log(n))$$ requires $$d(n)=o(1).$$ ---------- Last but not least, ...
$P$ is the set of all even words on {0,1}. Hi, i tried using pumping lemma to see why $L$ isn't a context-free language, but there's a decomposition where none of all three properties is violated ($|v|$ and $|x|$ iterating factors on $c^n$.). I know this doesn't mean it's context-free, but to be sure it is not...
Why $L$ = { $uc^nu$ | $u$ ∈ $P$, $n > 0$ } isn't context-free?
|context-free|pumping-lemma|
$P$ is the set of all words of even length on {0,1}. Hi, i tried using pumping lemma to see why $L$ isn't a context-free language, but there's a decomposition where none of all three properties is violated ($|v|$ and $|x|$ iterating factors on $c^n$.). I know this doesn't mean it's context-free, but to be sure...
There is no problem using the pumping lemma here. Assume that $L$ is context-free. Let $n$ be its pumping length and $u = 1^n0^nc1^n0^n\in L$. By the pumping lemma, there exists a decomposition $u = vwxyz$ such that: 1. $|wxy|\leqslant n$; 2. $|wy| > 0$; 3. for all $k\geqslant 0$, $vw^kxy^kz\in L$. Let u...
I was reading about the longest path problem and it is NP Complete. What about the problem where we need to find a path of some exact length $K$. All edges are directed. We are also allowed to repeat edges and vertices and all paths are positive. The reason is where ever I look they in the definition emphasize: ...
Is this variant of Exact Path Problem easy
|algorithms|
The reason for simple paths is simple (pun not intended): - either there is a cycle of positive weight, and therefore the longest path is not really defined as it could have an infinite weight; - or all cycles have non-positive weight, and the longest path is a simple path. As for weight values, if you can find a ...
I was reading about the longest path problem and it is NP Complete. What about the problem where we need to find a path of some exact length $K$. All edges are directed. We are also allowed to repeat edges and vertices and all weights are positive. The reason is where ever I look they in the definition emphasize: ...
I was reading about the longest path problem and it is NP Complete. What about the problem where we need to find a path of some exact length $K$. All edges are directed. We are also allowed to repeat edges and vertices and all weights are positive. The reason is where ever I look they in the definition emphasize...
|algorithms|complexity-theory|
Is this variant of Exact Path Length Problem easy or NP Complete
null
{"Voters":[{"Id":79440,"DisplayName":"Nathaniel"}]}
It's NP-complete even with weights from $\mathbb N$, and polytime for unweighted. Reference: _On the difficulty of finding walks of length $k$_, Basagni, Bruschi, Ravasio (1997). The reduction is from Subset Sum (it's not trivial to see how it is even in NP, since a walk can be exponential in the input size), but...
The reason for simple paths for the longest path problem is simple (pun not intended): - either there is a cycle of positive weight, and therefore the longest path is not really defined as it could have an infinite weight; - or all cycles have non-positive weight, and the longest path is a simple path. As for weig...
{"Voters":[{"Id":79440,"DisplayName":"Nathaniel"}]}
The reason for simple paths for the longest path problem is simple (pun not intended): - either there is a cycle of positive weight, and therefore the longest path is not really defined as it could have an infinite weight; - or all cycles have non-positive weight, and the longest path is a simple path. As for weig...
any reference on what kind of problem it is and what algorithm can solve this in $n^2\log n$? for 5 as d, the numbers 4 and 3 and 0 would work. so i think there should be zero in the array. maybe use naive approach($O(n^4)) memoize the raising to power 2 and adding up the results to decrease the running time? ...
given an integer array of length n, find tuples $(a,b,c,d)$ such that $d=\sqrt{a^2+b^2+c^2}$
|algorithms|