getSubsetsOfValues

fun <T> getSubsetsOfValues(elements: List<T>, includeCompleteSet: Boolean = false, includeEmptySet: Boolean = false): List<List<T>>

Generates subsets of the input list based on specified inclusion criteria.

Return

List of all generated subsets, where each subset is represented as a list

Example:

val input = listOf(1, 2, 3)
val subsets = getSubsetsOfValues(input) // Returns: [[1], [2], [3], [1,2], [1,3], [2,3]]

Implementation details:

  • Uses bit manipulation for efficient subset generation

  • Each number from 1 to 2^n-1 represents a unique subset combination

  • The i-th bit in the mask determines if the i-th element is included

Time Complexity: O(n * 2^n) where n is the number of elements Space Complexity: O(n * 2^n) for storing all subsets

Parameters

elements

The input list of elements to generate subsets from

includeCompleteSet

Whether to include the complete set (all elements) in the result (default: false)

includeEmptySet

Whether to include the empty set in the result (default: false)