Algorithm or expression to put n elements in k sets

Click For Summary

Discussion Overview

The discussion revolves around finding an algorithm or mathematical expression to partition a given number of elements into a specified number of sets. The focus includes both the methodology for partitioning and considerations for the sizes of the sets.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes having 17 elements and wanting to partition them into 3 sets, specifically with 2 sets of 6 elements and 1 set of 5 elements, seeking an algorithm or mathematical expression for this task.
  • Another participant suggests that there are many ways to partition n elements into k sets and questions whether the set sizes should be similar, proposing a naive approach of distributing n/k elements per set, noting potential issues with non-integer results.
  • A different participant proposes a method of adding one element at a time to each set in a cyclic manner, indicating that if the number of elements is not a multiple of the number of sets, the last cycle will not complete.
  • Another participant raises the idea of a 'distance' function to quantify similarity between items, suggesting that this could relate to clustering problems and mentions a possible algorithm for implementation.

Areas of Agreement / Disagreement

Participants express various methods and considerations for partitioning elements into sets, indicating that multiple competing views remain without a consensus on a single approach or algorithm.

Contextual Notes

Participants do not fully resolve the implications of set size uniformity or the specifics of the clustering problem, leaving these aspects open for further discussion.

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
 
Physics 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:

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
3
Views
2K
  • · Replies 20 ·
Replies
20
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 3 ·
Replies
3
Views
5K