Question: String Permutations Write a recursive function that outputs all permutations of a string1 . Include your function in a program that inputs a word (string
String Permutations Write a recursive function that outputs all permutations of a string1 . Include your function in a program that inputs a word (string with no spaces), and calls the function to output all permutations. A recursive algorithm to output all permutations of a string is as follows: Function receives two parameters; a string, and the number leading fixed characters in the string (only the characters beyond the fixed characters are to be permuted). Split the string into a fixed part and a variable part. Using a count-controlled loop for the number of characters in the variable part: ? Call the function recursively, passing the concatenation of the fixed part and the variable part as the string, and the number of fixed characters plus 1 as the number of fixed characters. ? Remove the first character from the variable part and concatenate it to the end of the string. When you initially call the function, pass the number of fixed characters as zero. When the function is called with the number of fixed characters equal to the size of the string, you have a new permutation. Output the permutation
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
