The Collections.permutations(List<T>) method is currently eager: it generates all permutations of the list and returns a list of these. However, it would be better to lazily generate the permutations.
Proposed Solution
We should return an Iterator<List<T>> which returns a different input permutation, generating the permutations on the fly, ideally without consuming O(n!) memory.
Problem to Solve
The
Collections.permutations(List<T>)
method is currently eager: it generates all permutations of the list and returns a list of these. However, it would be better to lazily generate the permutations.Proposed Solution
We should return an
Iterator<List<T>>
which returns a different input permutation, generating the permutations on the fly, ideally without consumingO(n!)
memory.