instruction stringlengths 0 29.8k ⌀ |
|---|
The problem is: split the given array with $L$ elements, $A$, into $K$ subsets such that maximum sum of all subsets is minimum. I have known that the problem that partitioning the multiset $S$ into two subsets $S_1$, $S_2$ such that the difference between the sum of elements in $S_1$ and the sum of elements in $S_2$ i... |
How to prove this variant of set partition problem is NP hard? |
|algorithms|np-hard| |
Here is a proof. I don't know if you'll find it in any paper since it is quite simple.
Consider the decision version of your problem: given a (multi-)set $A=\{a_1, \dots, a_L\}$ of $L$ elements, a positive integer $K$, and an integer $z$ decide whether there exists a partition of $A$ into $K$ sets $S_1, \dots, S_K$ ... |
Here is a proof that the problem is weakly NP-hard. I don't know if you'll find it in any paper since it is quite simple.
Consider the decision version of your problem: given a (multi-)set $A=\{a_1, \dots, a_L\}$ of $L$ elements, a positive integer $K$, and an integer $z$ decide whether there exists a partition of $... |
Here is a proof that the problem is weakly NP-hard. I don't know if you'll find it in any paper since it is quite simple.
Consider the decision version of your problem: given a (multi-)set $A=\{a_1, \dots, a_L\}$ of $L$ elements, a positive integer $K$, and an integer $z$ decide whether there exists a partition of $... |
Here is a proof that the problem is weakly NP-hard. I don't know if you'll find it in any paper since it is quite simple.
Consider the decision version of your problem: given a (multi-)set $A=\{a_1, \dots, a_L\}$ of $L$ elements, a positive integer $K$, and an integer $z$ decide whether there exists a partition of $... |
If you have no real criteria, you could do something like:
```
Input: couples (a1, n1), (a2, n2), …, (ak, nk)
Output: alternating array containing n1 occurrences of a1,
n2 occurrences of a2, …, nk occurrences of ak
for i = 1 to k:
mi ← ni
A ← empty array
while not all mi = 0:
let i ∈ {1, …... |
If you have no real criteria, you could do something like:
```
Input: couples (a1, n1), (a2, n2), …, (ak, nk)
Output: alternating array containing n1 occurrences of a1,
n2 occurrences of a2, …, nk occurrences of ak
for i = 1 to k:
mi ← ni
A ← empty array
while not all mi = 0:
let i ∈ {1, …... |
Given a series of n numbers, I need an algorithm that runs in worst case O(n^2) to figure out how many arrangements of those n numbers will give me a score of exactly k.
The score is calculated by the number of smaller numbers an element in the series has before it.
For example, the score of the below series wou... |
Is there an efficient way to solve this problem? |
|algorithms|dynamic-programming| |
Given a series of n numbers, I need an algorithm that runs in worst case O(n^2) to figure out how many arrangements of those n numbers will give me a score of exactly k.
The score is calculated by the number of smaller numbers an element in the series has before it.
For example, the score of the below series wou... |
Given a series of n numbers, I need an algorithm that runs in worst case O(n^2) to figure out how many arrangements of those n numbers will give me a score of exactly k.
Note that the series does not contain duplicate elements.
The score of a series of numbers is calculated by the number of smaller numbers an ele... |
Given a series of n numbers, I need an algorithm that runs in worst case O(n^2) to figure out how many arrangements of those n numbers will give me a score of exactly k.
Note that the series does not contain duplicate elements.
The score of a series of numbers is calculated by the number of smaller numbers an ele... |
null |
null |
Given a series of n numbers, I need an algorithm that runs in worst case O(n^2) to figure out how many arrangements of those n numbers will give me a score of exactly k.
**Note that the series does not contain duplicate elements.**
The score of a series of numbers is calculated by the number of smaller numbers an... |
Note that the values contained in the series are not important, and you can consider those values are exactly $1, 2, …, n$ (because only relative order is important).
Denote $A(n, k)$ the number of arrangements of $n$ values to reach score $k$.
Given an arrangement of $n$ values of score $k$, if you add the value... |
In my discussion, I will assume that the $|V|$ vertices of the DAG are represented as integers $0,1,..., |V|-1$ so they can be used as indices of an array. In case, different "labeling" is used, all arrays used in the solution can be replaced by any dictionary structure. Also, it is assumed that the DAG is represented ... |
In my discussion, I will assume that the $|V|$ vertices of the DAG are represented as integers $0,1,..., |V|-1$ so they can be used as indices of an array. In case, different "labeling" is used, all arrays used in the solution can be replaced by any dictionary structure. Also, it is assumed that the DAG is represented ... |
I would like to ask a very fundamental question regarding distance-regular graphs. Denote $d(u,v)$ as the distance between node $u$ and $v$. Distance-regular graphs are graphs such that for any pair of vertices $u,v$ with $d(u,v)=i$, there are always $b_i$ neighbors $w$ of $u$ with $d(w,v)=i+1$ and $c_i$ neighbors $w$ ... |
Can distance-regular graphs with different intersection arrays have the same number of k-hop neighbors for all k? |
|graphs|combinatorics| |
My professor mentioned that if we already know the divide and conquer algorithm for the closest pair of points in 2 dimensions it's easy to think of a similar algorithm for the 3 dimensions. But I am a bit confused as to what changes we have to make.
I think we'll divide the points in two sets based on the x coordin... |
Closest pair of points in 3D |
|algorithms|divide-and-conquer| |
$O(n^2 log n)$ is easy: Create a sorted array of the items in the first row. Lookup the items in the second row in this array using binary search, and remove items that were not present. Same with the third row etc. The last remaining item is the largest one present in evert row. The main effort is $n^2$ lookups in an ... |
Conflict-Free Replicated Datatypes (CRDTs) are a class of distributed data structures where replica states are allowed to temporarily diverge, but will eventually converge (in the absence of network partitions). [2]
Specifically, the class of CRDTs known as *state-based* (or *convergent*) achieved the above by requi... |
Proof that state-based (convergent) CRDTs are causally-consistent |
|data-structures|distributed-systems|consistency-model| |
I was solving a coding question which boiled down to this problem.\
Given a bipartite graph $G=\{V\cup U,E\}$. There is a positive value given for every node in $U$.\
Now we have to find the matching in which the sum of value of every node in $U$ which is also in the matching is maximum.\
Consider an example, Let v... |
As you say, you can split the points in two sets $A$ and $B$ of roughly the same size, depending on whether their $x$ coordinate smaller than or at least some threshold $x_0$. Solve the problem recursively on $A$ and $B$ and let $\delta$ be the minimum distance between any two points in the same set.
Now, instead of... |
The 2D approach you know probably uses sorting. Here I describe how to do it without sorting. This approach is straightforward to generalize to higher dimensions.
Below, "$\delta$-close" means "the distance is at most $\delta$"
We divided the points based on the $x$-coordinate, found $\delta$, and now it remains... |
As you say, you can split the points in two sets $A$ and $B$ of roughly the same size, depending on whether their $x$ coordinate smaller than or at least some threshold $x_0$. Solve the problem recursively on $A$ and $B$ and let $\delta$ be the minimum distance between any two points in the same set.
Now, instead of... |
There are integer tuples which index cells of a sparse multi-dimensional array (points inside n-parallelepiped).
The array itself is a BST with keys formed as $key = (...((a_0 * S_1 + a_1) * S_2 + a_3 ) * ... + a_{n-1}) * S_{n-1} + a_{n-1}$,
such keys preserve the order of tuples and can be compared in constant ... |
Order-preserving hashtable for integer tuples |
|time-complexity|data-structures|space-complexity|hash|hash-tables| |
There are integer tuples which index cells of a sparse multi-dimensional array (points inside n-parallelepiped).
The array itself is a BST with keys formed as $key = (...((a_0 * S_1 + a_1) * S_2 + a_3 ) * ... + a_{n-1}) * S_{n-1} + a_{n-1}$,
such keys preserve the order of tuples and can be compared in constant ... |
Here is an algorithm that is based on a simple idea and also works for directed and graphs having integer weights between $1$ and $W$.
Let $A$ be adjacency matrix of the graph.
Let $A^h$ denote the matrix obtained by multiplying $A$ $h$ times using via the min-plus matrix multiplication.
The entry at coordinate... |
Here is an algorithm that is based on a simple idea and also works for directed and graphs having integer weights between $1$ and $W$.
Let $A$ be adjacency matrix of the graph.
Let $A^h$ denote the matrix obtained by multiplying $A$ $h$ times using via the min-plus matrix multiplication.
The entry at coordinate... |
{"Voters":[{"Id":6759,"DisplayName":"Steven"}]} |
[This paper](https://www.sciencedirect.com/science/article/pii/S0022000085710781) shows how to solve the problem in time $O(n^{\omega} \log n)$, where $\omega < 2.372$ is the [matrix multiplication exponent](https://en.wikipedia.org/wiki/Computational_complexity_of_matrix_multiplication).
This means that you have a ... |
{"Voters":[{"Id":6759,"DisplayName":"Steven"}]} |
- Hash the first row and associate a flag to every element. $O(n)$.
- For the next rows,
- Reset all flags $O(n)$,
- Scan the row and set the flags of the elements already in the hash $O(n)$,
- Delete the elements with a flag reset $O(n)$.
In the end, you are left with the values that appear in eve... |
I would like to ask this question as I am not sure about the answer.
Let $G=(V,E)$ be a connected, undirected graph, and let $x,y\in V$ be two different vertices. Let $A$ be the problem of finding the shortest simple path between $x$ and $y$, and let $B$ be the problem of finding the longest simple path between $x$ ... |
A question about the graph theory or data structure and algorithms |
|algorithms|graphs|data-structures| |
Problem $A$ can be solved in polynomial time. Problem $B$ is NP-hard.
This means that options 2, 4, and 5 are false.
Option 3 is currently true (but wight become false in the future if P is proven to be equal to NP). We don't know whether $1$ is true. If it is true is, then P=NP.
If P=NP (but we don't have a pr... |
- Hash the first row and associate a flag to every element. $O(n)$.
- For the next rows,
- Reset all flags $O(n)$,
- Scan the row and set the flags of the elements already in the hash $O(n)$,
- Delete the elements with a flag reset $O(n)$.
In the end, you are left with the values that appear in eve... |
Problem $A$ can be solved in polynomial time. Problem $B$ is NP-hard.
This means that options 2, and 5 are false.
We don't know whether option 1 is true. If it is true is, then P=NP.
Option 3 is currently true (but might become false in the future if P is proven to be equal to NP).
Option 4 is currently fal... |
- Hash the first row and associate a flag to every element. $O(n)$.
- For the next rows,
- Reset all flags $O(n)$,
- Scan the row and set the flags of the elements already in the hash $O(n)$,
- Delete the elements with a flag reset $O(n)$.
In the end, you are left with the values that appear in eve... |
Problem $A$ can be solved in polynomial time. Problem $B$ is NP-hard.
This means that options 2 and 5 are certainly false.
We don't know whether option 1 is true. If it is true is, then P=NP.
Option 3 is currently true (but might become false in the future if P is proven to be equal to NP).
Option 4 is curr... |
// Let's look at the number 11201 in base 3
// which we will represent as (11201),3
//
// (11201),3 = ( ),7
//
// 3^4 3^3 3^2 3^1 3^0
// 1 1 2 0 1
//
// The "amount" of number we have in any given base
// can be computed... |
null |
// Let's look at the number 11201 in base 3
// which we will represent as (11201),3
//
// (11201),3 = ( ),7
//
// 3^4 3^3 3^2 3^1 3^0
// 1 1 2 0 1
//
// The "amount" of number we have in any given base
// can be computed... |
There are integer tuples which index cells of a sparse multi-dimensional array (points inside n-parallelepiped).
The array itself is a BST with keys formed as $key = (...((a_0 * S_1 + a_1) * S_2 + a_3 ) * ... + a_{n-1}) * S_{n-1} + a_{n-1}$,
such keys preserve the order of tuples and can be compared in constant ... |
Given a series of n numbers, I need an algorithm that runs in worst case O(n*k) to figure out how many arrangements of those n numbers will give me a score of exactly k.
**Note that the series does not contain duplicate elements.**
The score of a series of numbers is calculated by the number of smaller numbers an... |
Given a series of n numbers, I need an algorithm that runs in worst case **O(n*k)** to figure out how many arrangements of those n numbers will give me a score of exactly k.
**Note that the series does not contain duplicate elements.**
The score of a series of numbers is calculated by the number of smaller number... |
There are integer tuples which index cells of a sparse multi-dimensional array (points inside n-parallelepiped).
The array itself is a BST with keys formed as $key = (...((a_0 * S_1 + a_1) * S_2 + a_3 ) * ... + a_{n-2}) * S_{n-1} + a_{n-1}$,
such keys preserve the order of tuples and can be compared in constant ... |
null |
I am looking for an algorithm to find the best order of items to fit on pages.
Consider the following case, we have a page with the *height = 300*
We have images with the following heights - *[150,200,100,150,300]*
So I want to find the best order for this images in order to fill the page.
For example:
**First... |
Algorithm to find best order for items on pages with a fixed height |
|algorithms|algorithm-analysis|sorting|search-algorithms| |
This sounds like it might be the [bin packing problem](https://en.wikipedia.org/wiki/Bin_packing_problem). If so, the problem is NP-complete, but there are many methods for heuristics, approximation algorithms, etc., which you can read about and apply in your setting. |
null |
There are integer tuples which index cells of a sparse multi-dimensional array (points inside n-parallelepiped).
The array itself is a BST with keys formed as $key = (...((a_0 * S_1 + a_1) * S_2 + a_3 ) * ... + a_{n-2}) * S_{n-1} + a_{n-1}$,
such keys preserve the order of tuples and can be compared in constant ... |
It seems that I have found such pair of distance-regular graphs, which are illustrated below. They both have 20 vertices.
The first graph is the Desargues Graph and the second is the Dodecahedron.
[![enter image description here][1]][1]
[![enter image description here][2]][2]
[1]: https://i.stack.imgur.com/... |
null |
There are integer tuples which index cells of a sparse multi-dimensional array (points inside n-parallelepiped).
The array itself is a BST with keys formed as $key = (...((a_0 * S_1 + a_1) * S_2 + a_3 ) * ... + a_{n-2}) * S_{n-1} + a_{n-1}$,
such keys preserve the order of tuples and can be compared in constant ... |
A bit confused about the term minimum bottleneck spanning tree. I thought it was the spanning tree with the cheapest maximum edge, but the example I was given seems to contradict this.
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/WEtD0.png
In the example above, my material says:
... |
what is the minimum bottleneck spanning tree here? |
|minimum-spanning-tree| |
I'm the author of GateBoy (a gate-level simulation of the original Game Boy hardware) and Metron (a C++ to Verilog translation tool). One big issue I had to work around for both projects is the inability of C++ (or really, any current procedural programming language) to express atomic state change in a way that is both... |
Is “x' = f(x)” a programming paradigm? |
|programming-languages|functional-programming|programming-paradigms| |
Suppose we have a matrix $A$ of dimension $n \times n$ and 2 vectors $\vec{u}$ and $\vec{v}$ of dimension $n$.
Then we have $A\vec{v} = \vec{x}$ with time complexity $O(n^2)$ and space complexity $O(n)$ with the naive algorithm (since the output is a vector of length $n$)
(forgive me if there is a better runtime ... |
Can dot producting the result of vector-matrix multiplication speed up the runtime |
|complexity-theory|time-complexity|runtime-analysis|linear-algebra|matrix-multiplication| |
Suppose we have a matrix $A$ of dimension $n \times n$ and 2 vectors $\vec{u}$ and $\vec{v}$ of dimension $n$.
Then we have $A\vec{v} = \vec{x}$ with time complexity $O(n^2)$ and space complexity $O(n)$ with the naive algorithm (since the output is a vector of length $n$)
(forgive me if there is a better runtime ... |
About few ago in my freshman year of college I stumbled across an [an old blog post](https://veniamin-ilmer.github.io/ship-city) on r/programming posing a programming challenge. Here is the short version of it:
> Hundreds of ships would like to dock to each other to build a floating city of ships.
>
> Although th... |
Possible approaches to the Ship City problem? |
|algorithms|optimization|combinatorics| |
No. It is not possible to reduce the time complexity below $O(n^2)$ time. It takes $\Theta(n^2)$ time just to read every entry in $A$. Moreover, the result depends on every entry of $A$ (if there is any entry that the algorithm doesn't read, then the algorithm will produce the wrong output on some inputs). Conseque... |
how to count all pairs such that w^x=y^z, where 1<=w,x,y,x<=n and 1<=n<=1000000
for example for n=3, there is 15 solutions
1^1=1^1
1^1=1^2
1^1=1^3
1^2=1^1
1^2=1^2
1^2=1^3
1^3=1^1
1^3=1^2
1^3=1^3
2^1=2^1
2^2=2^2
2^3=2^3
3^1=3^1
3^2=3^2
3^3=3^3 |
how to count all pairs such that w^x=y^z, where 1<=w,x,y,x<=n and 1<=n<=1000000 |
|algorithms|dynamic-programming|number-theory|counting| |
The solution for the all-pair shortest path problem on unweighted and undirected graph |
If you expand your expression, the result is a linear combination of the terms of the outer product of $\vec u$ and $\vec v$, where the coefficients are the elements of $A$. So all these terms are independent and must all be evaluated.
A similar reasoning shows that the matrix/vector also has $\Omega(n^2)$ complexit... |
I am no good at giving names to paradigms. Someone else will be. But the answer to what you actually want to do is quite straightforward, in C++ at least.
Basically you accumulate **actions**, and having accumulated them you execute them all at the end. In the example you give, each action is of the form "set `a` to... |
I am research scholar currently working in complexity theory. Recently, i have started working on hard proofs and reductions. It is very well established that there is a polynomial reduction from every known hard problem to a possible hard problem. So, while proving the hardness of a problem, it does not matter which h... |
Choosing the ideal problem to prove the hardness |
|complexity-theory|graphs|reductions|np-hard|polynomial-time-reductions| |
Experience and luck. But also having a list of NP-complete problems that you reduce from, and go through one by one exhaustively. Then, of course, you try to prove that the problem can be solved in polynomial time. Then you repeat.
You will, with experience, learn how to come up with gadgets that "propagate" info... |
There are integer tuples which index cells of a sparse multi-dimensional array (points inside n-parallelepiped).
The array itself is a BST with keys formed as $key = (...((a_0 * S_1 + a_1) * S_2 + a_3 ) * ... + a_{n-2}) * S_{n-1} + a_{n-1}$,
such keys preserve the order of tuples and can be compared in constant ... |
As you say, you can split the points in two sets $A$ and $B$ of roughly the same size, depending on whether their $x$ coordinate smaller than or at least some threshold $x_0$. Solve the problem recursively on $A$ and $B$ and let $\delta$ be the minimum distance between any two points in the same set.
Now, instead of... |
As you say, you can split the points in two sets $A$ and $B$ of roughly the same size, depending on whether their $x$ coordinate smaller than or at least some threshold $x_0$. Solve the problem recursively on $A$ and $B$ and let $\delta$ be the minimum distance between any two points in the same set.
Now, instead of... |
null |
I build a python script which uses OpenCV implementation of KNN Backgroud Segmentation/Remover.
I know the basics of how KNN works, but not how the background segmentation works.
For the MOG algorithm I found lots of papers, but I havn't found a single one for KNN background segmentation. Apart from wanting to und... |
Details about KNN based background segmentation |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.