Class Permutations
java.lang.Object
topics.backtracking.permutations.Permutations
Permutations Generation
This class exhaustively generates all possible permutations of an ordered mathematical set containing N distinct integer elements. It employs a Backtracking paradigm to construct valid sequences dynamically.
Complexity
- Time Complexity:
O(N!)- Generating all permutations of N elements requires factorial time, as the algorithm explores every unique arrangement across the state space tree. - Space Complexity:
O(N)- Requires linear space to store the domain vector, the boolean tracking array, the partial solution vector, and the activation records on the JVM stack.
- Author:
- vicegd
-
Constructor Summary
ConstructorsConstructorDescriptionPermutations(int setSize) Initializes the state tracking structures to generate permutations for a set of integers from0toN-1. -
Method Summary
Modifier and TypeMethodDescriptionvoidTriggers the recursive backtracking engine to generate all permutations.intRetrieves the total count of permutations generated by the algorithm.
-
Constructor Details
-
Permutations
public Permutations(int setSize) Initializes the state tracking structures to generate permutations for a set of integers from0toN-1.- Parameters:
setSize- The total number of elements (N) in the domain.
-
-
Method Details
-
generateAll
public void generateAll()Triggers the recursive backtracking engine to generate all permutations. -
getPermutationCount
public int getPermutationCount()Retrieves the total count of permutations generated by the algorithm.- Returns:
- The integer count of valid permutations.
-