0
$\begingroup$

I have a sequence $s$ of rational numbers where $|s|=n$. I am given a percentage $p$ to partition the sequence $s$ into $\frac{1}{p}$ parts, such that each part contains $p\%$ number of elements of the whole sequence.

However, it becomes problematic for certain $n$ and $p$ combinations. For example, for $n=50$ and $p=5\%$, we are supposed to obtain 20 parts/sub-sequences. If we have $3$ elements per part, we will only have 17 of them while the last one contains only $2$ elements. If we have $2$ elements per part, we will have 20 of them but the last one will contain $12$ elements.

The purpose of partitioning the sequence in the first place is to calculate the mean for each resulting sub-sequence, i.e. that of first $p\%$, that of second $p\%$, and so on.

So what is a good way to deal with this situation?

  • 0
    @i.m.soloveichik, $p$ is given and I have to use that.2012-08-30

1 Answers 1

1

Obviously you can't divide it up exactly in these cases, so you have to approximate. If you have a set of $n$ elements to be partitioned into $m$ subsets, you can write $n = mq + r$ where $q = \lfloor n/m \rfloor$ and $r \in \{0,1,\ldots,m-1\}$. You can then take $m-r$ subsets of size $q$ and $r$ subsets of size $q+1$.