## Given a row sum vector and a column sum vector, determine if they can form a boolean matrix

For example, for a boolean matrix of size $$3×4$$, the row sum vector $$R = (3, 3, 0, 0)$$ and the column sum vector $$C = (2, 2, 2)$$ form a match because I can construct the boolean matrix:

$$\begin{matrix} & \begin{bmatrix} 1 & 1 & 0 & 0\ 1 & 1 & 0 & 0\ 1 & 1 & 0 & 0 \end{bmatrix} & \begin{pmatrix} 2\2\2 \end{pmatrix} = C \ R = &\begin{pmatrix} 2 & 2 & 0 & 0 \end{pmatrix} \end{matrix}$$

However, the column vector $$C’ = (4, 1, 1)$$ doesn’t form a match with $$R$$.

So given two vectors whose values are sorted in descending order $$R_{1, w}$$ and $$C_{h, 1}$$, and whose accumulated sum is the same, $$T = \sum_jR[1, j] = \sum_iC[i, 1]$$, how can I polynomically check if $$R$$ and $$C$$ form a matching because I can form a matrix $$M_{h,w}$$ having $$R$$ and $$C$$ as row and column sum vectors?

More specifically, in case it can help to make the check algorithm faster, in my specific case, R and C has the following properties:

• $$h \leq w$$
• The number of positive values of $$R$$ and $$C$$ is $$> w$$. For example, $$R$$, in the example, has two positive values and $$C$$ has three positive values, and it happens that $$2 + 3 > w = 4$$.

## Finding the most frequent element, given that it’s Theta(n)-frequent?

We know [Ben-Or 1983] that deciding whether all elements in an array are distinct requires $$\Theta(n \log(n))$$ time; and this problem reduces to finding the most frequent element, so it takes $$\Theta(n \log(n))$$ time to find the most frequent element (assuming the domain of the array elements is not small).

But what happens when you know that there’s an element with frequency at least $$\alpha \cdot n$$? Can you then decide the problem, or determine what the element is, in linear time (in $$n$$, not necessarily in $$1/\alpha$$) and deterministically?

## How to compute a vector V when N points are given and V satisfies given properties

We are given N points P1,P2,…,PN in a 2D plane(All points are distinct and N is as large as 10^5). For each valid i, the coordinates of the point Pi are (xi,yi). Help me to find a vector V = (a, b) ( where |a|, |b| <= 1e9) such that the following holds:

For each i (1 ≤ i ≤ N), let Si= dot(V, G(Pi, Pi+1)). lets assume PN+1=P1. where G(v1, v2) = ((v2(x) – v1(x)), (v2(y) – v1(y)) and dot(V1, V2) denotes dot product of two vectors

How to choose V such that It is possible to find two integers l and r (1 ≤ l ≤ r ≤ N) such that:

Si < 0 if(i <= r and i >= l) and Si > 0 otherwise

(or)

Si > 0 if(i <= r and i >= l) and Si < 0 otherwise

I need to know if there is a way of choosing vector (a, b) to satisfy the above conditions(If the solution is possible)

## Determine if there is a subset of the given set with sum divisible by a given integer

I’ve been given a question to solve:

Given a set of non-negative distinct integers, and a value $$m$$, determine if there is a subset of the given set with sum divisible by $$m$$.

For this question the answer is here

I don’t understand the part after if DP[j]==True
what is actually the intuition behind this code. Please explain in detail.

## Reduce the number of final states for the given NSFA?

For the given NFA, how do you reduce the number of paths without adding $$\epsilon$$-transitions?

## What is the largest sum that can be constructed with the given recipes?

There are $$n$$ sets of distinct positive integers, $$S_1,\ldots,S_n$$. There is a set of recipes that allows us to construct tuples of integers from these sets. For example, the recipe {1,2} allows us to construct tuples of two integers: one from $$S_1$$ and one from $$S_2$$. Each integer can be used in at most one tuple. What is an algorithm that, given the sets and the recipes, constructs tuples such that the sum of integers in all tuples together is maximum? Here are some simple cases:

(a) There is a single recipe, e.g. {1,2}. Then the algorithm is simple: sort the integers in $$S_1$$ and in $$S_2$$ in descending order; pair the largest integers in each set; pair the second-largest integers in each set; keep pairing integers as long as the sum of the next pair is positive.

(b) There are two recipes {1,2} and {1,3}. Then, $$S_2$$ and $$S_3$$ are substitutes: combine them into a single set $$S_4 = S_2\cup S_3$$, and proceed as in (a) with the recipe {1, 4}.

(c) There are two recipes {1,2} and {1,3,4}. Then, $$S_3$$ and $$S_4$$ are complements: sort each one in descending order, and construct a new set $$S_5$$ in which the largest element is the sum of the largest elements in $$S_3,S_4$$, the second-largest is the sum of the two second-largest elements, and so on. Proceed as in (b) with the recipes {1,2} and {1,5}.

(d) The above two operations can be generalized to the case in which the set of recipes has a tree structure: there is a tree in which each node is a set, and each recipe is a path from root to leaf in the tree. The tree can be "contracted" as follows: a leaf which is the unique child of its parent can be combined with its parent as in (c); two leafs of the same parent can be combined as in (b).

Is there an efficient algorithm that works for any set of recipes?

## Choosing an AI method to recreate a given binary 2D image

If the title wan not very clear, I want a method to take an input image like this,

[[0, 0, 0, 0],  [1, 1, 1, 0],  [1, 1, 1, 0],  [0, 1, 1, 0]] 

and output the 2D coordinates of the 1s of the image (So that I can recreate the image)

I want the output to be sequential because I need to reconstruct the input image pixel by pixel and there are some conditions on the image construction order (e.g. You cannot place a 1 somewhere when it is surrounded by 1s)

The image can change and the number of 1s in the image too.

1. What is an appropriate AI method to apply in this case?
2. How should I feed the image to the network? (Will flattening it to 2D affect my need of an output order?)
3. Should I get the output coordinates one by one or as an ordered 2xN matrix?
4. If one by one, should I feed the same image for each output or the image without the 1s already filled?

EDIT: The application is a robot creating the image using some kind of building blocks, placing one block after the other

I have tried to apply "NeuroEvolution of Augmenting Topologies" for this using neat-python but was unsuccessful. I am currently looking at RNNs but I am not sure if it is the best choice either.

## Algorithm for drawing the horizon given the current coordinates, elevation and field of view

I have a large database containing coordinates along with an elevation number. If I am a person looking in some direction (0-360) with an n degree field of view, and located at some coordinate and at some elevation, how can I generate an image representing the horizon? What algorithm should I use?

## Given a plot of a network Graph[] how can the {x,y} screen coordinates be output?

Is there a general way to get the screen or "world" coordinates for every vertex in the graphic output of something like this?

Table[Graph[Table[i \[UndirectedEdge] i + 1, {i, 20}],    GraphLayout -> l,    PlotLabel -> l],  {l, {"CircularEmbedding", "SpiralEmbedding"}}] 

Trying to build an algorithm to generate novel layouts and want to use a large amount of other algorithms for training data.

## Minimizing cost of a given sequence by partitoning [closed]

Given a sequence of positive integers of size N(let) divide it into at most K(K > N/C) disjoint parts/subsequences in order to minimize the "cost" of the entire sequence.

Partitions cannot overlap, for example [1,2,3,4,5] can be divided into [1,2], [3,4] and [5] but not [1,3] and [2,4,5].

The cost of a subsequence is computed as the number of repeated integers in it. The cost of the entire sequence is computed as the sum of costs of all the subsequences and a fixed positive integer cost C times the number of partitions/divisions of the original sequence.

How should I go about determining the position and number of partitions to minimize the total cost?

Some more examples:

The given list = [1,2,3,1] Without any partitions, its cost will be 2 + C, as 1 occurs two times and the original sequence is counted as one partition.

[1,1,2,1,2] Without any partitions, its cost will be 5, as 1 occurs three times and 2 occurs two times. If we divided the subsequence like so [1,1,2],[1,2] then the cost becomes 2 + 2*C, where C is the cost of partitioning.

I have actually solved the problem for the case of C = 1, but am having problems generalizing it to higher values of C.

For C = 1 it makes sense to partition the sequence while traversing it from one direction as soon as a repetition occurs as the cost of a single repetition is 2 whereas the cost of partitioning is 1.

I’m trying to solve it in nlog(n) complexity ideally or at most a fast n^2.