Question
Can you submit a method based off this pseudocode? Pseudocode: ALGORITHM GeneratePermutations(n) //Input: A positive integer //Output: A list of all permutations of {0, ,
Can you submit a method based off this pseudocode?
Pseudocode: ALGORITHM GeneratePermutations(n)
//Input: A positive integer
//Output: A list of all permutations of {0, , 1}. Each permutation is an array.
Initialize an empty list of permutations.
If n=0,
Create an array of length 0.
Add it to the list of permutations.
Return the list of permutations.
Otherwise,
Call GeneratePermutations(n-1).
The recursive call returns a list of permutations of the numbers 0 through n-2.
Call this the list of subpermutations.
For each subpermutation in the list:
Initialize an array of length n; call it p.
Copy the subpermutation into the first n-1 elements of p
Enter n-1 into the last position of p.
For i=0 to n-2:
Create a copy of the array p.
Add the copy to the list of permutations.
Swap p[n-i-1] with p[n-i-2].
Add p to the list of permutations.
Return the list of permutations
____________________________________________________________________
I just would like the method above but
The original java code is:
public class AlgLab4 { public static void main(String[] args) { printPerms(generatePermutations(3)); printAnagrams("frog"); } public static void printAnagrams(String s) { //student implementation } public static ArrayList
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started