Class Permutations

java.lang.Object
topics.backtracking.permutations.Permutations

public class Permutations extends Object

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

    Constructors
    Constructor
    Description
    Permutations(int setSize)
    Initializes the state tracking structures to generate permutations for a set of integers from 0 to N-1.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Triggers the recursive backtracking engine to generate all permutations.
    int
    Retrieves the total count of permutations generated by the algorithm.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Permutations

      public Permutations(int setSize)
      Initializes the state tracking structures to generate permutations for a set of integers from 0 to N-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.