Algorithm or expression to put n elements in k sets

AI Thread Summary
To partition 17 elements into 3 sets with specified sizes, an algorithm can be designed to distribute elements evenly, such as assigning n/k elements per set and adjusting for non-integer results. A cycling method can be employed, where elements are added one at a time to each set until the total is reached, accommodating any remainder by stopping early. The discussion also highlights the importance of considering a 'distance' function to group similar items together, suggesting that this could relate to clustering problems. Implementing a clustering algorithm could effectively address the need for similarity in set assignments. Overall, the conversation emphasizes the flexibility in partitioning strategies based on set size requirements and element characteristics.
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...
Suppose ,instead of the usual x,y coordinate system with an I basis vector along the x -axis and a corresponding j basis vector along the y-axis we instead have a different pair of basis vectors ,call them e and f along their respective axes. I have seen that this is an important subject in maths My question is what physical applications does such a model apply to? I am asking here because I have devoted quite a lot of time in the past to understanding convectors and the dual...
Back
Top