Permutations excluding repeated characters
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Permutations excluding repeated characters are a fascinating and essential concept in combinatorics and computer science. These permutations have wide-ranging applications, from solving puzzles to running algorithms efficiently. This article will delve into the technical details, present examples, and provide a comprehensive understanding of permutations with unique elements.
Introduction to Permutations
In mathematics, permutations refer to the various ways in which elements of a set can be arranged. When considering permutations of a set with distinct elements, each arrangement must be unique. For example, all possible arrangements of the set `{A, B, C}` are permutations of the three distinct characters: `ABC`, `ACB`, `BAC`, `BCA`, `CAB`, and `CBA`.
Mathematical Foundation
The formula for finding the total number of permutations of a set of distinct elements is given by:
Where `$!$`, or factorial, denotes the product of all positive integers up to `n`. If the set contains 3 distinct characters, its permutations can be calculated as:
This factorial formula only applies to sets without repeated elements. If characters repeat, the formula needs modification to account for indistinguishable arrangements.
Examples of Permutations
Permutations of a 3-Character Set
Consider the set `{A, B, C}`. The distinct permutations are as follows:
• `ABC` • `ACB` • `BAC` • `BCA` • `CAB` • `CBA`
Permutations of a Word
Permutations apply to more practical examples, such as rearranging the letters in a word. For the word "DOG":
- `DOG`
- `DGO`
- `ODG`
- `OGD`
- `GDO`
- `GOD`
With each character being unique, the total permutations are computed as , yielding 6 permutations.
Application of Permutations
Permutations play a key role in fields like cryptography, where patterns and ordering are critical. They also appear in algorithms used to identify paths or settings in solving puzzles, such as the classic Rubik's Cube.
Additionally, permutation algorithms are utilized for generating sequences in test cases and data arrangement tasks in computer science.
Algorithms for Generating Permutations
One of the commonly used algorithms for generating permutations in programming languages involves recursive techniques. A recursive function permutes one character at a time, swapping elements, generating a new permutation, and subsequently backtracking:
Related reading
- Permutations of a binary tree
- Permutations of binary number by swapping two bits not lexicographically
- Permutations via Heap's algorithm with a mystery comma
- Permutations without recursive function call
- Permutations of letters and numbers in a phone number
- Picking a random element from a set
- Peterson algorithm in Java?
- Phonetically Memorable Password Generation Algorithms

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.