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 generatePermutations(int n) { } } } return list; } public static void printPerms(ArrayList perms) { for (int[] p : perms) { System.out.print("["); for (int e:p) System.out.print(" "+e); System.out.println(" ]"); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!