top of page

Program To Find All The Permutations Of A String

Arranging and rearranging elements are a part of our daily lives. Whether it is about arranging students in a row or just simply setting up your passwords, permutation and combinations surrounds us everywhere.


Well, this is the reason you hear about it a lot in your math class or coding class. However, finding permutations and combinations becomes a bit tricky in coding.


Therefore, along with other questions related to strings like string palindrome in Java, permutations are often asked by an interviewer.


Do not worry if you are not familiar with the concept of finding all the permutations of a string!


We have got you covered.


Check out all the possible methods to find the permutations of the given string in this post.


Understand Permutation


What is permutation?


This question may seem a bit surprising to you but there are still many people who are not familiar with the term.


Therefore, before everything else, let’s understand what permutations are.

Simply said, a permutation is a process of arranging the elements of a set into some order or sequence. In case the set is already arranged, permutation includes rearranging all the elements.


Let’s make it more clear with an example:


Consider that you are given the following set: {1, 2, 3}

Now, this set will have 6 permutations. They are:

  • (1, 3, 2)

  • (2, 3, 1)

  • (3, 1, 2)

  • (1, 2, 3)

  • (2, 1, 3)

  • (3, 2, 1)

Hopefully, now you have a clear understanding of what permutation is and how you can find it for the given set of elements. Now let’s begin with finding a permutation of a string.


Problem Statement


A string S will be provided to you. You will have to print every possible permutation of the String S. The permutation of the string is another string in which all the elements of the string are present. However, the order of the elements can be different.

For instance, you are given the string “abcd”. One of the permutations of this string can be “dabc”. These two strings will then read more...

Recent Posts

See All

Comments


Drop Me a Line, Let Me Know What You Think

Thanks for submitting!

© 2023 by Train of Thoughts. Proudly created with Wix.com

bottom of page