Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions

Question

BUS3ENT Individual Business Plan

Answered: 1 week ago