[Solved] 2 Permutations 30 Points Mplement Class Works Like Iterator Geserates Possible Permutation Q37257042
java program
2 Permutations (30 points) mplement a class that works like an iterator and geserates all possible permutations of a list It cannot actually le an Iterator, becwase the official Java Iterstor interface looks ke the following public isterface Iteratorc t public boolean haextO public E next O public void emoveO The next) method of a Java iterator returas an element of a collection, but our permnstatio getarator ist return a wkle ๒. Neverthdax we wil adapt the medalis a Pesatations object that impkments the folloming three methods (at ast) iteratots. Create public class PerautationcE public Persutations(LiatCE liat) public boolean haaext O public ListcE next O able to call the coastractor with an iary list. Theu Notice the ifference? We should be achitrary list. Then as long as bas Nest)retuas tre, we shoald be able to call nest) and gt a ew perutation of our list The easiest way to grseste peratations is (not surprisingl) reeursively. The algorithm creating a Pernastations object is as ollows (Base case) If 1 am a Pemutations object of list leugth O, do nothing, exept to note that should always return Eabe when ha Next is called Recursive c) Remove and remember the first element (c) from the lis e Create and remember a new Permutationess object (P) with the letover bs Olbtain and remember the Eirst permutation (L.) from this nw objnct, or an caupty list if it hae sone (becanse it is sie 0) Initialise an index couner(i) to. Each tie the neat met hod is caled con a Peoutations object, it should do the following Retarn a copy of L with e inserted at position LIncrement .Os er l breeans too large, set L1) Prit()and rest İtoeL . If P has no int per mutation, then this object ﹄hled as well, has Cat O saald return false froan here on out Here’s how it works for the list . 1, 2 Issert 0 into each position in the ist Thus saco sive calls to 뻬() return io, 1, 2㎛0.21. Il, 2,0.RZlRo,1]-421.0 After tlus last lat 볘 let urned, hasNext() should ieturu take. Hint: The list you return should be a wwly-ceated ooe, either a LinkedL.ist or an AayLt your choice), with elesments copied over. Don’t try to use the same list that you were given in the constructor, because you’d be disaseembling it and sebling it a mliple evels o reeursion and it’s almost impossible to lavp it straight and do it right Extra Credit: You shoald really think about doing this one, becase it’s a geat way to test your Peruutations object Use your Permutat ions objeect to impesmeut the exponential NP soet that we taloed abost in class. Generate all of the permutalt los of a list in turn, checking each oe to see if t’s soete. Stop when you find the seeted list. How long a list can you sort sing this algoeitban, before the t it talors becomes intolerable Show transcribed image text 2 Permutations (30 points) mplement a class that works like an iterator and geserates all possible permutations of a list It cannot actually le an Iterator, becwase the official Java Iterstor interface looks ke the following public isterface Iteratorc t public boolean haextO public E next O public void emoveO The next) method of a Java iterator returas an element of a collection, but our permnstatio getarator ist return a wkle ๒. Neverthdax we wil adapt the medalis a Pesatations object that impkments the folloming three methods (at ast) iteratots. Create public class PerautationcE public Persutations(LiatCE liat) public boolean haaext O public ListcE next O able to call the coastractor with an iary list. Theu Notice the ifference? We should be achitrary list. Then as long as bas Nest)retuas tre, we shoald be able to call nest) and gt a ew perutation of our list The easiest way to grseste peratations is (not surprisingl) reeursively. The algorithm creating a Pernastations object is as ollows (Base case) If 1 am a Pemutations object of list leugth O, do nothing, exept to note that should always return Eabe when ha Next is called Recursive c) Remove and remember the first element (c) from the lis e Create and remember a new Permutationess object (P) with the letover bs Olbtain and remember the Eirst permutation (L.) from this nw objnct, or an caupty list if it hae sone (becanse it is sie 0) Initialise an index couner(i) to. Each tie the neat met hod is caled con a Peoutations object, it should do the following Retarn a copy of L with e inserted at position LIncrement .Os er l breeans too large, set L1) Prit()and rest İtoeL . If P has no int per mutation, then this object ﹄hled as well, has Cat O saald return false froan here on out Here’s how it works for the list . 1, 2 Issert 0 into each position in the ist Thus saco sive calls to 뻬() return io, 1, 2㎛0.21. Il, 2,0.RZlRo,1]-421.0 After tlus last lat 볘 let urned, hasNext() should ieturu take. Hint: The list you return should be a wwly-ceated ooe, either a LinkedL.ist or an AayLt your choice), with elesments copied over. Don’t try to use the same list that you were given in the constructor, because you’d be disaseembling it and sebling it a mliple evels o reeursion and it’s almost impossible to lavp it straight and do it right Extra Credit: You shoald really think about doing this one, becase it’s a geat way to test your Peruutations object Use your Permutat ions objeect to impesmeut the exponential NP soet that we taloed abost in class. Generate all of the permutalt los of a list in turn, checking each oe to see if t’s soete. Stop when you find the seeted list. How long a list can you sort sing this algoeitban, before the t it talors becomes intolerable
Expert Answer
Answer to 2 Permutations (30 points) mplement a class that works like an iterator and geserates all possible permutations of a lis… . . .
OR

