Algorithm or expression to put n elements in k sets

xeon123
Messages
90
Reaction score
0
I have 17 elements, and I want to put them in 3 sets. This makes 2 sets with 6 elements, and 1 set with 5 elements. Now I want to find an algorithm to partition n elements in k sets.

Can anyone give me an algorithm, or a math expression for me to implement in a algorithm?

Thanks
 
Mathematics news on Phys.org
There are many ways to put n elements in k sets. Do you want the set sizes to be similar to each other?
A naive approach would be n/k elements per set. This is not always an integer, but you can fix this by rounding in an appropriate way.
 
You could add 1 element at a time to each set, cycling through all the sets as you add elements. If the number of elements isn't an multiple of the number of sets, you just run out of elements before cycling through all the sets on the last cycle.
 
Is there a 'distance' function, a way to quantify how close or how similar two items are (so that you place similar items in the same set)? (Examples would be assigning customers to their closest service center, or grouping objects of similar colors.)

If this sounds like the case, it may be a clustering problem; one possible algorithm, not difficult to implement, could be this one. (Or, for a clearer explanation that Wikipedia, see here.)
 
Last edited:
Insights auto threads is broken atm, so I'm manually creating these for new Insight articles. In Dirac’s Principles of Quantum Mechanics published in 1930 he introduced a “convenient notation” he referred to as a “delta function” which he treated as a continuum analog to the discrete Kronecker delta. The Kronecker delta is simply the indexed components of the identity operator in matrix algebra Source: https://www.physicsforums.com/insights/what-exactly-is-diracs-delta-function/ by...
Fermat's Last Theorem has long been one of the most famous mathematical problems, and is now one of the most famous theorems. It simply states that the equation $$ a^n+b^n=c^n $$ has no solutions with positive integers if ##n>2.## It was named after Pierre de Fermat (1607-1665). The problem itself stems from the book Arithmetica by Diophantus of Alexandria. It gained popularity because Fermat noted in his copy "Cubum autem in duos cubos, aut quadratoquadratum in duos quadratoquadratos, et...
Thread 'Imaginary Pythagorus'
I posted this in the Lame Math thread, but it's got me thinking. Is there any validity to this? Or is it really just a mathematical trick? Naively, I see that i2 + plus 12 does equal zero2. But does this have a meaning? I know one can treat the imaginary number line as just another axis like the reals, but does that mean this does represent a triangle in the complex plane with a hypotenuse of length zero? Ibix offered a rendering of the diagram using what I assume is matrix* notation...
Back
Top