This problem is interesting and I am looking forward to other's solution with some known promising algorithm to solve this problem...Meanwhile I will just give my thoughts.
I do not know what data structure your ordered set is but
I have a simple thought if I did not understand your question wrongly:
Maybe we can just use a simple recurssive with the recursive formula as follow
Split(ordered set A){
if(len(A) == 1) print(A[0])
string group = "";
for(int i in [1, len(A)]){
group = group+" "+A[i];
A remove A[i];
print(group + "," + Split(A));
}
}
Basically it is looping the set, from first element to last element, at each iteration, take the first i element as first partition, then remove these i elements, call same function again (recursion) (Depends on your data structure, you may not need physically removed but only pass a segment of the set A, anyway it's the concept)
The performance is slow this way but I think it maybe acceptable considering you have to get all combinations.
You may speed this up with some twist: Indeed we only need to know the size of the set to get the partitions, for the first 4 elements, or middle 4 consecutive elements, or 4 consecutive elements anywhere in the set, they all can be partitioned with the same way. So we indeed only need to save all the ways to partition a set with n elements, which can enhanced the above recursion to dynamic programming:
vector<vector<int>> pos[n];
// pos[i] is my way to store the "configuration" of the partition for i elements
// for example: pos[7] may store [[1,3,7], [2,4,7]]
// Means (1..1),(2..3),(4..7) is one way to partition 7 elements
// (1..2),(3..4),(5..7) is another way
// I want to find pos with this dynamic programming method
Split(int size){
if(pos[size] is not empty){
return pos[size];
}
if(size == 1){
push [1] into pos;
return pos;
}
vector<vector<int>> ret;
for(int i in [1..n]){
vector<vector<int>> subPartitions= Split(n-i);
for(vector<int> partition in [1..size(subPartitions)]){
Add i (offset) to all element in partition
vector<int> newPartition = Merge([i], parition);
push newPartition to ret;
}
}
return pos[size] = ret;
}
It is a high level conceptual pseudo code, depends on data structure and implementation it may solve your problem with acceptable performance.
abca valid partition of{a,b,c}? Isabcda valid partition of{a,b,c,d}? In other words outputting the set of tokens with no brackets(ab)(cd)?