Enumerate all k-partitions of 1d array with N elements?

Posted by user301217 on Stack Overflow See other posts from Stack Overflow or by user301217
Published on 2010-12-30T14:48:13Z Indexed on 2010/12/30 14:54 UTC
Read the original article Hit count: 95

Filed under:
|
|
|
|

This seems like a simple request, but google is not my friend because "partition" scores a bunch of hits in database and filesystem space.

I need to enumerate all partitions of an array of N values (N is constant) into k sub-arrays. The sub-arrays are just that - a starting index and ending index. The overall order of the original array will be preserved.

For example, with N=4 and k=2:

[ | a b c d ] (0, 4)
[ a | b c d ] (1, 3)
[ a b | c d ] (2, 2)
[ a b c | d ] (3, 1)
[ a b c d | ] (4, 0)

I'm pretty sure this isn't an original problem (and no, it's not homework), but I'd like to do it for every k <= N, and it'd be great if the later passes (as k grows) took advantage of earlier results.

If you've got a link, please share.

© Stack Overflow or respective owner

Related posts about java

Related posts about c