Deprecated: class-phpmailer.php is deprecated since version 5.5.0! Use wp-includes/PHPMailer/PHPMailer.php instead. The PHPMailer class has been moved to wp-includes/PHPMailer subdirectory and now uses the PHPMailer\PHPMailer namespace. in /opt/bitnami/apps/wordpress/htdocs/wp-includes/functions.php on line 4967
Print all permutations of a string using Python - CodeRefer Blog
Notice: Trying to get property 'display_name' of non-object in /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/wordpress-seo/frontend/schema/class-schema-person.php on line 152

Notice: Trying to get property 'user_email' of non-object in /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/wordpress-seo/frontend/schema/class-schema-person.php on line 230

Notice: Trying to get property 'display_name' of non-object in /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/wordpress-seo/frontend/schema/class-schema-person.php on line 236
Home Algorithms Print all permutations of a string using Python

Print all permutations of a string using Python

0
Print all permutations of a string using Python

In this article we will discuss how to print all permutations of a given String using Python programming Language.

Before diving into the program, let us first see what is a Permutation.

Permutation

A permutation is the rearrangement of the characters of a string. Let us take an example of the string “ABC”. Here the permutations of the respective string are ABC ACB BAC BCA CBA CAB.

Useful Links:

 

Below is the recursion tree using backtrack to find Permutations.

Program

Now let us see the Python Program to print all the permutations of a string.

Time Complexity

Now let us analyse the time complexity of the above backtracing algorithm used. Here the time taken to print a permutation is n as it has to travel down to the depth of n to print a permutation. No of permutations of a string of size n is n! Hence the total time to print all the permutations is O(n x n!)

 

0 0 vote
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x