Class SubsetsIterator<T>

java.lang.Object
com.amalgamasimulation.core.combinatorics.SubsetsIterator<T>
Type Parameters:
T - the type of elements in the input lists and the subsets produced by this iterator
All Implemented Interfaces:
Iterator<List<T>>

public class SubsetsIterator<T> extends Object implements Iterator<List<T>>
An iterator over all possible subsets of the provided list of elements. Each subset is represented as a list of elements, and the list includes all subsets ranging from the empty set to the full set of the input list. This class provides an iterative approach to generating and traversing each subset, without generating all of them in memory upfront.

For example, if the input list is [1, 2], the result would include [], [1], [2], and [1, 2].

Returned list is ordered, order of elements is always the same for the same input. Order of elements in every returned subset is the same as in the original list.

Author:
Andrey Malykhanov
See Also:
  • Constructor Details

    • SubsetsIterator

      public SubsetsIterator(List<? extends T> elements)
      Creates a new instance of an iterator over all possible subsets of the provided list of elements
      Parameters:
      elements - list of elements
      See Also:
  • Method Details