# Processor distribution and proportional apportionment

I saw an interview problem about assigning identical processors to embarrassingly parallel jobs. The running time of a job equals the running time on a single processor divided by the number of processors. We are interested in minimizing the maximum running time. Formally, we get the following problem.

Given positive reals $a_{1},…,a_{n}$ and positive integer $k$, find non-negative integers $x_{1},…,x_{n}$, such that $∑_{i}x_{i}≤k$ and $θ=max_{i}a_{i}/x_{i}$ is minimized.

If there is no integral requirement on $x_{i}$’s, then the problem is easy. Let $A=∑_{i}a_{i}$. There is a closed solution of $x_{i}=kAa_{i} $, and $θ=A/k$.

Otherwise, it is easy to check if $θ_{′}>0$ is a feasible solution. $θ_{′}$ is feasible iff $∑_{i}⌈a_{i}/θ_{′}⌉≤k$. Therefore one can apply binary search, and get the result in $O(ngk)$ time.

One can also get a $O(ngn)$ time algorithm. First compute $y_{i}=⌈kAa_{i} ⌉$. Greedily find a $i$ such that $a_{i}/y_{i}$ is maximized, and decrease $y_{i}$ by $1$. We stop when we have $∑_{i}y_{i}=k$. This takes $O(gn)$ per operation using a binary search tree.

Linear time algorithm also exists. It is connected to proportional apportionment. This is the problem of finding the smallest $λ$, such that $∑_{i}⌈λa_{i}⌉=k$. Cheng and Eppstein found a $O(n)$ time algorithm [1]. Reitzig and Wild found a simpler algorithm later [2].

There is a similar interview problem. Given $n$ points on the real line, add $k$ more points, such that it minimizes the maximum length between adjacent points. The problem is the same as the following one.

Given positive $a_{1},…,a_{n}$ and positive integer $k$, find non-negative integers $x_{1},…,x_{n}$, such that $∑_{i}x_{i}≤k$ and $θ=max_{i}a_{i}/(x_{i}+1)$ is minimized.

The linear time algorithm for proportional apportionment should also work for the above problem. It is interesting how much can we change the problem before the linear time algorithm no longer works.

# References

**Building fences straight and high: An optimal algorithm for finding the maximum length you can cut $k$ times from given sticks**, Algorithmica. (2017) 10.1007/s00453-017-0392-3.