Author: Giannis Loizou
Description: Generates all permutations of the set {1, 2, ..., n} using a tree-based approach.
This project implements an original approach to generating permutations in lexicographic order using a linked tree structure.
- Each node represents an element of the set.
- Children represent subsequent elements in the permutation.
- The
mixerfunction recursively swaps root elements to generate all permutations.
This implementation demonstrates:
- Custom tree data structures
- Breadth-first traversal
- Lexicographic permutation generation without using Python's built-in
itertools.permutations
- Construct a tree with all possible permutation paths
- Print each permutation in lexicographic order
- Interactive command-line program
- Modular, object-oriented design (abstract
Treeclass and concreteLinkedTreeclass)
-
Clone the repository: git clone https://github.com/Hydrocast/Lexicographic-Permutations-Tree.git
-
cd LexicographicPermutationsTree
-
Run the program: python3 permutations_tree.py
-
Enter a positive integer n when prompted. The program will display all permutations of {1, 2, ..., n} in lexicographic order.
Enter a positive integer n: 3
{ 1, 2, 3 }
{ 1, 3, 2 }
{ 2, 1, 3 }
{ 2, 3, 1 }
{ 3, 1, 2 }
{ 3, 2, 1 }