0 1 2 0 2 1 1 0 2 1 2 0 2 1 0 2 0 1Here is the method recursiveGenPerms.
public static void recursiveGenPerms(int n, int[] perms, int m) { if (m == n) { printArray(perms, n); return; } for(int i = 0; i < n-m; i++) { swap(perms, m, m+i); recursiveGenPerms(n, perms, m+1); swap(perms, m, m+i); } }
0 0 1 0 1 0 0 0 1 0 1 0 1 0 0 1 0 0Notice that the output contains repeats - the first and the third permutation are identical and so are the last two. Ideally, the output should be
0 0 1 0 1 0 1 0 0This problem asks you to modify the function recursiveGenPerms so that it outputs only distinct permutations of a given sequence, of possibly non-distinct integers. Use the following idea: each distinct element should be placed exactly once in slot m of perms before the recursive call is made. For example, if (0, 2, 0, 1) is the input array then we should place each of 0, 1, and 2 in slot 0 exactly once and generate all permutations of the rest of the elements in the rest of the slots.
To simplify your code you may assume that the input array will only contain integers in the range 0 through n-1, where n is the size of the array. For example, if n = 4, the input array will contain integers between 0 and 3, though it may contain multiple occurances of some of these integers. Using the idea and the assumption mentioned above it took me about 4 additional lines of code to get recursiveGenPerms working.
(A, 0) (B, 2) (C, 0) (D, 0) (E, 2) (F, 0) (G, 0) (H, 1).Here each item consists of a name and a priority. Notice that all priorities are integers in the range [0, 2]. Draw a picture of the betterMinHeap object after all insert operations are completed. Clearly, indicate the values of all your data members.
Stack<Node<E>> s = new Stack<Node<E>>(); int numProcessed = 0;Use the following function header for the next method:
public E next()
List the data members of the LevelOrderTreeIterator class.
Then implement the next() method for the
LevelOrderTreeIterator class.
(Hint: Recall breadth-first search.)