org.matheclipse.combinatoric
Class MultisetCombinationIterator
- java.lang.Object
-
- org.matheclipse.combinatoric.MultisetCombinationIterator
-
- All Implemented Interfaces:
- java.util.Iterator<int[]>
public class MultisetCombinationIterator extends java.lang.Object implements java.util.Iterator<int[]>Combinations of a multiset
These are the combinations of
kelements chosen from a sortedint[]array, that can contain duplicates (a multiset).For example, given the multiset
{0, 1, 1, 2, 2, 2, 3}, the 4-combinations are:[0, 1, 1, 2] [0, 1, 1, 3] [0, 1, 2, 2] [0, 1, 2, 3] [0, 2, 2, 2] [0, 2, 2, 3] [1, 1, 2, 2] [1, 1, 2, 3] [1, 2, 2, 2] [1, 2, 2, 3] [2, 2, 2, 3]
This algorithm produces the combinations in lexicographic order, with the elements in each combination in increasing order.
Begin with the first combination, which is the first k elements of the multiset ([0, 1, 1, 2] in the example above), and then at each step:
- Find the rightmost element that is less than the maximum value it can have (which is the element in the multiset that is the same distance from the right).
- Replace it with the first multiset element greater than it.
- Replace the remainder of the combination with the elements that follow the replacement in the multiset.
-
-
Constructor Summary
Constructors Constructor and Description MultisetCombinationIterator(int[] multiset, int k)Combinations of a multiset
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanhasNext()int[]next()voidremove()Throws an UnsupportedOperationExceptionvoidreset()
-
-
-
Constructor Detail
-
MultisetCombinationIterator
public MultisetCombinationIterator(int[] multiset, int k)Combinations of a multiset
These are the combinations of
kelements chosen from a sortedint[]array, that can contain duplicates (a multiset).
-
-
Method Detail
-
reset
public void reset()
-
next
public int[] next()
- Specified by:
nextin interfacejava.util.Iterator<int[]>- See Also:
Iterator.next()
-
hasNext
public final boolean hasNext()
- Specified by:
hasNextin interfacejava.util.Iterator<int[]>- See Also:
Iterator.hasNext()
-
remove
public void remove()
Throws an UnsupportedOperationException- Specified by:
removein interfacejava.util.Iterator<int[]>
-
-
DMelt 3.0 © DataMelt by jWork.ORG