instruction
stringlengths
0
29.8k
⌀
|clustering|minimax|
null
As pointed out in this [answer](https://cs.stackexchange.com/a/159420/101305), the problem is hard. Moreover the problem is infact APX-hard (see [here](https://arxiv.org/abs/1307.2521)). [This](https://cs.stackexchange.com/a/159418/101305) does infact provide an interesting insight by showing an easy reduction to se...
Let $A,B$ be the two sides of the bipartite graph, we are looking for a subuset of $A$. Hall's characterization of perfect matchings states that $G$ admits a perfect matching saturating $A$ if and only if for each subset $X\subseteq A$ it holds that $|N(X)|\geq |X|$. If the graph admits a perfect matching, then acco...
As pointed out in this [answer](https://cs.stackexchange.com/a/159420/101305), the problem is hard. Moreover the problem is infact APX-hard (see [here](https://arxiv.org/abs/1307.2521)). [This](https://cs.stackexchange.com/a/159418/101305) does infact provide an interesting insight by showing an easy reduction to se...
Let $A,B$ be the two sides of the bipartite graph, we are looking for a subuset of $A$. Hall's characterization of perfect matchings states that $G$ admits a perfect matching saturating $A$ if and only if for each subset $X\subseteq A$ it holds that $|N(X)|\geq |X|$. If the graph admits a perfect matching, then acco...
As pointed out in this [answer](https://cs.stackexchange.com/a/159420/101305), the problem is hard. Moreover the problem is infact APX-hard (see [here](https://arxiv.org/abs/1307.2521)). Also, the problem is commonly known as the point-line-cover (PLC) in the literature. [This](https://cs.stackexchange.com/a/159418/...
Let the absolute errors on all variables be equal to $\delta$. The absolute errors on the differences are $2\delta$ and the relative errors on the second term is $$\frac{2\delta}{x-a_x}+\frac{2\delta}{b_y-a_y}+\frac{2\delta}{b_x-a_x}$$ So the final absolute error, $$\delta\left(1+2\frac{(x-a_x)(b_y-a_y)}{b_...
From Chapter 35 of Introduction to Algorithms by Cormen et al. > EXACT-SUBSET-SUM is an exponential-time algorithm in general, although it is a polynomial-time algorithm in the special cases in which $t$ is polynomial in $|S|$ or all the numbers in $S$ are bounded by a polynomial in $|S|$. I fail to see the reaso...
Polynomial Time Special Case of Subset Sum Problem
|algorithms|subset-sum|
In the [book][1] "Introduction to Algorithms" by Cormen, Leiserson, Rivest, and Stein. in chapter 8 Lemma 8.4 is proved. (my question is after the proof of the lemma) > Given n b-bit numbers and any positive integer $r≤b$, RADIX-SORT correctly sorts these numbers in $Θ((b/r)(n+2^r))$ time if the stable sort it uses...
The value of $r$, with $r≤ b$, that minimizes the expression $(b/r)(n+2^r)$ in the analysis of the radix-sort algorithm
|algorithm-analysis|optimization|radix-sort|
#### Bitlength and bound needed for two's complement > Prove that for $A, B \in \mathbb{Z}$, $A + B$ $= (A\operatorname{\&}B) + (A \mid B)$ $= (A \oplus B) + 2(A\operatorname{\&}B)$ where $\operatorname{\&}$ is bitwise AND, $\mid$ is bitwise OR and $\oplus$ is bitwise XOR. (It is reasonable to assume that the bit r...
In the [book][1] "Introduction to Algorithms" by Cormen, Leiserson, Rivest, and Stein. in chapter 8 Lemma 8.4 is proved. (my question is after the proof of the lemma) > Given n b-bit numbers and any positive integer $r≤b$, RADIX-SORT correctly sorts these numbers in $Θ((b/r)(n+2^r))$ time if the stable sort it uses...
null
null
Recently I came across a problem I don't get may hands on: Given p binary positions. Let s be the number of "set-bits" (1 < s < p * 2^(p-1) - 1). I need the maximal set of assigments that alltogether set s bits. Example: p = 3, s = 8. ==> A "maximal" set: {(0,0,1), (0,1,0), (1,0,0), (0,1,1), (1,0,1)} A...
Assignment problem with maximal partitioning
|algorithms|optimization|sets|assignment-problem|
You can greedily add elements from least bits set to most until you have more than $s$ total bits and then remove one of the elements (based on their number of set bits) to fix it. To only count the number of elements you can sum $ \binom{p}1 + 2\binom p 2 + 3\binom p 3 + ...$ until it is greater than $s$, then figu...
So I am gonna to have 2 sorted arrays which will have the same length. I need to find the two median values from the union of the two arrays which need to be sorted, and I need to do this in O(log n). I was able to come up with finding the median in log(n) but that is without sorting the arrays, I could use one of the ...
How can I find 2 median values of an array which is an union of 2 arrays in O(log n)?
|algorithms|algorithm-design|
null
For fixed $n$, let $f(r)=(b/r)(n+2^r)$ where $r>0$. Since $f(r)>(b/r)n$, $\ f(0^+)=\infty$. Since $f(r)>(b/r)2^r$, $\ f(\infty)=\infty.$ Hence there exists $m$ such that $f(r)$ reaches its global minimum at $r=m$. By the extreme value theorem, we have $$f'(m)=0,$$ which means $-\frac b{m^2}(n+2^m)+\frac bm(2^m...
null
Suppose we have a problem, $A$, and a machine $T_A$ that solves $A$. Now, let's say we have a problem $B$ that is solvable with a polynomial number of calls to $T_A$, and we call $T_B$ the machine that solves $B$ by calling $T_A$. But $T_B$ solves $B$ with probability $\frac{2}{3}$. Does $B$ still reduce to $A$ ...
Reduction between problems where problem A solves problem B with probability $\frac{2}{3}$
|complexity-theory|reductions|polynomial-time-reductions|
In chapter 8 of the [book][1] "*Introduction to Algorithms*" by Cormen, Leiserson, Rivest, and Stein, lemma 8.4 is proved. (my question is after the proof of the lemma) > Given $n$ $b$-bit numbers and any positive integer $r≤b$, RADIX-SORT correctly sorts these numbers in $Θ((b/r)(n+2^r))$ time if the stable sort i...
|algorithm-analysis|optimization|asymptotics|radix-sort|
The original interpretation of dependent type theory in lcccs by Seely suffers from coherence problems. There are a range of techniques with have been invented to solve them. In most cases the interpretation of a type $\Gamma \vdash A \textit{ type}$ is no longer an object in the slice $\mathbf S/\Gamma$ over the inte...
There is a dependence on the length. For an _n_-bit CRC and a _k_-bit burst error, the probability of a false positive is _(2<sup>max(k – n, 0)</sup> – 1) / (2<sup>k</sup> – 1)_. One minus that is the probability of a _k_-bit burst error detection. In the limit, you get _1 – 2<sup>-n</sup>_.
null
You have mentioned the most useful data structure, the prefix sums. What you need is a way to pair each prefix sum of the first array with a prefix sum of the other array of a similar value. Then consider the difference among the pairs. ------ As you suspected, there always exists a solution. Let us use prefix su...
Consider the following problem: You are given two integer arrays $A$ and $B$ of size $N$ and $M$, respectively. You are guaranteed that $1 <= A[i] <= M$ and $1 <= B[i] <= N$ for all $i$ (so each array's elements is at most the other array's size). The sizes of the arrays, $N$ and $M$, may be up to $100,000$. Construct ...
Finding equal-sum subsets from two arrays
So I have 2 sorted arrays which will have the same length and what I need to do is sort the union array (the union of the two sorted arrays) and then find two median values, I need to do this in O(log n). I was able to come up with finding the median in log(n) but that is without sorting the arrays, I could use one of ...
Let $C_1, ..., C_m \in \mathbb{R}^n$ Is there a polynomial algorithm in $n,m$ which finds the Minimum Enclosing Ball (MEB) for these points? My research - I see mentions of algorithms like Megido, Waltz etc. which are known to solve the problem in linear time in $m$, the number of points, but these seem to be exp...
null
null
null
null
As pointed out in this [answer](https://cs.stackexchange.com/a/159420/101305), the problem is hard. Moreover the problem is infact APX-hard (see [here](https://arxiv.org/abs/1307.2521)). Also, the problem is commonly known as the point-line-cover (PLC) in the literature. [This](https://cs.stackexchange.com/a/159418/...
null
I'm assuming the two arrays are of size $n$ each. Now to unite them into a single sorted array one can use the merge procedure from Merge Sort (see [here](https://en.wikipedia.org/wiki/Merge_algorithm#Merging_two_lists)). This runs in $\Theta(n)$ which is asymptotically tight, that is you can not do better as you have ...
As pointed out in the comments by this [user](https://cs.stackexchange.com/users/683/yuval-filmus), under the standard rules of operator precedence and operator associativity every expression has a unique expression tree representation. Now every ordered tree (including expression tree) results into unique sequences wh...
It is an easy matter to check these identity that are true for single bits (the case $1+0$ follows by commutativity). $$0+0=0\land0+0\lor0=0\oplus0+2\,(0\land0)\\ 0+1=0\land1+0\lor1=0\oplus1+2\,(0\land1)\\ 1+1=1\land1+1\lor1=1\oplus1+2\,(1\land1)$$ And these results immediately generalize to bitwise operations ...
**Assume the pipeline is initially empty and the processor is given 8 instructions to execute. However, the 4th instruction is an instruction whose operands depend on the result of the previous instruction. The remaining instructions are independent of each other. Given the instructions are not re-ordered, how long doe...
Dependency in pipeline
|cpu|cpu-pipelines|
null
Recently I came across a problem I don't get may hands on: Given p binary positions. Let s be the number of "set-bits" (1 < s < p * 2^(p-1) - 1). I need the maximal set of assigments that alltogether set s bits. Example: p = 3, s = 8. ==> A "maximal" set: {(0,0,1), (0,1,0), (1,1,0), (0,1,1), (1,0,1)} A...
I cracked this problem a little bit. In fact, not using xorshift, bit using LFSR. As I wrote in the comments I want to use it as an alternative to the counter. LFSRs are in fact used as a counters, beacuse have simpler feedback logic than natural binary counters or Gray-code counters, and therefore can operate at highe...
Let $E$ be the set of your edges, and let $V$ be the set of all the edge's endpoints. Consider the graph $G=(V,E)$. You're asking for a [Directed Eulerian trail of $G$][1]. [One possible way][2] to so so, is the following: assume that each vertex has the same in- and out-degree (more on how this assumption can be ...
I have a digraph D on n vertices formed in the following manner: - I start with k ordered lists of integers, with each integer from 1-n in at least one list. Integers do not show up more than once in a given list. - I create a node for each integer, with an arc from node x to y iff x appears before y in at least ...
Finding a maximum induced DAG in a digraph
|algorithms|graphs|approximation|dag|
I have a digraph D on n vertices formed in the following manner: - I start with k ordered (not sorted) lists of integers, with each integer from 1-n in at least one list. Integers do not show up more than once in a given list. - I create a node for each integer, with an arc from node x to y if x appears before y ...
Consider all pairs of points in turn and detect all those that are collinear with them. This takes time $O(n^3)$ and will generate up to $\dfrac{(n-1)n}2$ subsets. This reduces the question to a set cover decision problem. ---------- For $k=2$, an easy solution in $O(n)$ is given by @JohnL: Pick $3$ points. O...
### The outline of some ideas. Since it is too slow to run through all subsets, we may restrict to subarrays of $A$ and $B$. The sum of numbers in a subarray can be computed readily as **the difference of two prefix-sums**. Towards two subarrays of equal sums, we would like to generate many pairs of prefix-sums, ...
Consider the following problem: You are given two integer arrays $A$ and $B$ of size $N$ and $M$, respectively. You are guaranteed that $1 <= A[i] <= M$ and $1 <= B[i] <= N$ for all $i$ (so each array's elements is at most the other array's size). The sizes of the arrays, $N$ and $M$, may be up to $100,000$. Construct ...
|algorithms|time-complexity|arrays|mathematical-analysis|subset-sum|
The general idea of the algorithm is pretty straightforward, it basically boils down to the dichotomic search idea by cutting your problem in half at each step. But the parity of the length of the arrays introduces some noisy intricacies. ## Notations * $X$ and $Y$ two sorted arrays of the same size (their starti...
**Assume the pipeline is initially empty and the processor is given 8 instructions to execute. However, the 4th instruction is an instruction whose operands depend on the result of the previous instruction. The remaining instructions are independent of each other. Given the instructions are not re-ordered, how long doe...
I cracked this problem a little bit. In fact, not using xorshift, bit using LFSR. As I wrote in the comments I want to use it as an alternative to the counter. LFSRs are in fact used as a counters, beacuse have simpler feedback logic than natural binary counters or Gray-code counters, and therefore can operate at highe...
Given a set of weighted permutations of numbers, an operation can be performed to combine multiple permutations that share numbers into a single rolled up permutation. What is the optimal algorithm to bucket the values into the minimal number of combined permutations? **Examples** permutation (weight) ...
Weighted permutation bucketting
|algorithms|permutations|
With the Circuit-SAT problem, I often see the "split" gate (I don't know the official name of it). This gate has a truth table of: $$ \begin{array}{|c |c c|} 0 & 0 & 0\\ 1 & 1 & 1\\ \end{array} $$ And it has a symbol of this: [![enter image description here][1]][1] This gate allows us to use variable n...
SAT with every variable occuring exactly once
|satisfiability|circuits|
I cracked this problem a little bit. In fact, not using xorshift, bit using LFSR. As I wrote in the comments I want to use it as an alternative to the counter. LFSRs are in fact used as a counters, beacuse have simpler feedback logic than natural binary counters or Gray-code counters, and therefore can operate at highe...
I do recall having found a book on software design patterns with a foreword by Christopher Alexander. Now, as is well known Alexander is credited as the creator of the concept of design patterns and design languages. In this particular text, he also described how he first came to know his work was being used in compute...
Reference request for book on design patterns with foreword by Christopher Alexander
|reference-request|design-patterns|
The general idea of the algorithm is pretty straightforward, it basically boils down to the dichotomic search idea by cutting your problem in half at each step. But the parity of the length of the arrays introduces some noisy intricacies. ## Notations * $X$ and $Y$ two sorted arrays of the same size (their starti...
null
The general idea of the algorithm is pretty straightforward, it basically boils down to the dichotomic search idea by cutting your problem in half at each step. But the parity of the length of the arrays introduces some noisy intricacies. ## Notations * $X$ and $Y$ two sorted arrays of the same size (their starti...
This does not work in lambda calculus. One of the rules for evaluating lambda calculus terms is [α-conversion](https://en.wikipedia.org/wiki/Lambda_calculus#%CE%B1-conversion), which allows variable names to be changed at any time for any reason, as long as they do not conflict. There's no way that a program can arrang...
Each variable would appear *twice* - once as an output to a gate and once as an input. It is trivial to start from the output and trace backwards, setting variables as you go, with a simple greedy algorithm. If the output has to be 1 then set it to 1. If the output of an AND or OR gate is 1 or 0, set all inputs to t...
A round of [Salsa20](https://en.wikipedia.org/wiki/Salsa20) is done as follows: ``` b ^= (a + d) <<< 7; c ^= (b + a) <<< 9; d ^= (c + b) <<< 13; a ^= (d + c) <<< 18; ``` The Salsa20 variant called ChaCha20 has its round function like this: ``` a += b; d ^= a; d <<<= 16; c += d; b ^= c; b <<<= 12; a ...
Does copying/moving data between variables consumes less cycles per byte than adding/rotating/xoring?
|performance|
null
Could it be <i>Patterns of Software</i> by Richard P. Gabriel (Oxford University Press, 1996)? Here's an excerpt from the foreword by Christopher Alexander: > A year or two ago, I was astonished to get several letters from different people in the computer science field, telling me that my name was a household word ...
null
Given a bipartite graph $G$ and an integer $l$, how many edge subsets of size $l$ are there such that the degree of each vertex is odd? Does anyone know if there is a polynomial-time algorithm for this problem?
Given a bipartite graph G and an integer l, how many edge subsets of size l are there such that the degree of each vertex is odd?
|complexity-theory|graphs|combinatorics|
NP-complete problems are the "hardest problems" in NP. This means that all other problems in NP reduce (in polytime) to these problems. A consequence of this is *if* we were to find some polynomial time algorithm to solve one of these problems, we could prove $P = NP$. And if we could prove that no polynomial time algo...
Are there problems in NP that would solve P vs NP, but are not NP complete
|complexity-theory|np-complete|np|p-vs-np|
null
NP-complete problems are the "hardest problems" in NP. This means that all other problems in NP reduce (in polytime) to these problems. A consequence of this is *if* we were to find some polynomial time algorithm to solve one of these problems, we could prove $P = NP$. And if we could prove that no polynomial time algo...
I am trying to understand which combinatorial problem best fits the one I have. I am mostly asking from the perspective of being pointed towards relevant literature. I will explain the problem with an example. Consider the set $S = \lbrace{a^1, a^2, a^3, b^1, b^2, b^3, b^4, c^1, d^1, d^2, d^3, d^4 \rbrace}$. So not...
Which combinatorial problem is reminiscent to mine?
|algorithms|approximation|heuristics|