A permutation is an arrangement of all or part of a set of objects, with regard to the order of the arrangement. For instance, the words ‘bat’ and ‘tab’ represents two distinct permutation (or arrangements) of a similar three-letter word.
Examples: 
 
Input: str = “cd”
Output: cd dc
Input: str = “abb”
Output: abb abb bab bba bab bba
Approach: Write a recursive function that prints every permutation of the given string. Termination condition will be when the passed string is empty.
Below is the implementation of the above approach:
:
abb abb bab bba bab bba
When the permutations need to be distinct.
Examples: 
 
Input: str = “abb”
Output: abb bab bba
Approach: Write a recursive function that prints distinct permutations. Make a boolean array of size ’26’ which accounts for the character being used. If the character has not been used then the recursive call will take place.
Otherwise, don’t make any calls. The termination condition will be when the passed string is empty.
Below is the implementation of the above approach:
without recursion
abba abab aabb baba baab bbaaDon't miss the next article!Be the first to be notified when a new article or Kubernetes experiment is published.

 
 
