
Write a method subsets that uses recursive backtracking to find every possible sub-list of a given list. A sub-list of a list L contains 0 or more of L's elements. Your method should accept a List of strings as its parameter and print every sub-list that could be created from elements of that list, one per line. For example, suppose a variable called list stores the following elements:
[Janet, Robert, Morgan, Char]
The call of subsets(list); would produce output such as the following:
[Janet, Robert, Morgan, Char]
[Janet, Robert, Morgan]
[Janet, Robert, Char]
[Janet, Robert]
[Janet, Morgan, Char]
[Janet, Morgan]
[Janet, Char]
[Janet]
[Robert, Morgan, Char]
[Robert, Morgan]
[Robert, Char]
[Robert]
[Morgan, Char]
[Morgan]
[Char]
[]
[3:07 AM]
The order in which you show the sub-lists does not matter, but the order of the elements of each sub-list DOES matter (Note: this requirement is a limitation of Practice-It testing code. The textbook version of the problem would accept an answer with the elements in any order). The key thing is that your method should produce the correct overall set of sub-lists as its output. Notice that the empty list is considered one of these sub-lists. You may assume that the list passed to your method is not null and that the list contains no duplicates. Do not use any loops in solving this problem.
Hint: This problem is somewhat similar to the permutations problem. Consider each element and try to generate all sub-lists that do include it, as well as all sub-lists that do not include it.
It can be hard to see a pattern from looking at the lines of output. But notice that the first 8 of 16 total lines of output constitute all the sets that include Janet, and the last 8 lines are the sets that do not have her as a member. Within either of those groups of 8 lines, the first 4 of them are all the sets that include Robert, and the last 4 lines are the ones that do not include him. Within a clump of 4, the first 2 are the ones including Morgan, and the last 2 are the ones that do not include Morgan. And so on. Once again, you do not have to match this exact order, but looking at it can help with figuring out the patterns and the recursion.
Type your solution here:

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- Using arrays or ArrayList in java language Write the method named mesh.* * Start with two ArrayLists of String, A and B, each with * its elements in alphabetical order and without any duplicates. * Return a new list containing the first N elements from the two * lists. The result list should be in alphabetical order and without * duplicates. A and B will both have a size which is N or more. * Your solution should make a single pass over A and B, taking * advantage of the fact that they are in alphabetical order, * copying elements directly to the new list.* * Remember, to see if one String is "greater than" or "less than" * another, you need to use the compareTo() method, not the < or > * operators. * * Examples:* mesh(["a","c","z"], ["b","f","z"], 3) returns ["a","b","c"]* mesh(["a","c","z"], ["c","f","z"], 3) returns ["a","c","f"]* mesh(["f","g","z"], ["c","f","g"], 3) returns ["c","f","g"]* * @param a an ArrayList of String in alphabetical order.* @param b an ArrayList of…arrow_forwardThink about the following example: A computer program builds and modifies a linked list like follows: Normally, the program would keep tabs on two unique nodes, which are as follows: An explanation of how to use the null reference in the linked list's node in two common circumstancesarrow_forwardWrite a programme that calls a method that accepts an integer array as a parameter (you may initialise an array in the main function) and returns the list's minimal value. Below is a partial programme. public class Min{ public static void main(String[] args){ int arr= System.out.print(minimum(arr)); }arrow_forward
- Need help writing a static method in Python that does the following: Given any two lists A and B, determine if:List A is equal to list B; orList A contains list B (A is a superlist of B); orList A is contained by list B (A is a sublist of B); orNone of the above is true, thus lists A and B are unequalSpecifically, list A is equal to list B if both lists have the same values in the sameorder. List A is a superlist of B if A contains a sub-sequence of values equal to B.List A is a sublist of B if B contains a sub-sequence of values equal to A.arrow_forwardWrite program in javaarrow_forwardIn python. Write a LinkedList class that has recursive implementations of the add and remove methods. It should also have recursive implementations of the contains, insert, and reverse methods. The reverse method should not change the data value each node holds - it must rearrange the order of the nodes in the linked list (by changing the next value each node holds). It should have a recursive method named to_plain_list that takes no parameters (unless they have default arguments) and returns a regular Python list that has the same values (from the data attribute of the Node objects), in the same order, as the current state of the linked list. The head data member of the LinkedList class must be private and have a get method defined (named get_head). It should return the first Node in the list (not the value inside it). As in the iterative LinkedList in the exploration, the data members of the Node class don't have to be private. The reason for that is because Node is a trivial class…arrow_forward
- Only 2arrow_forwardConstruct recursive versions of the library functions that: a. calculate the "sum" of a list of numbers. b. "take" a given number of elements from the beginning of a list. c. select the "last" element of a non-empty list .arrow_forwardHas to be done in Java, import ArrayListarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





