Question: Recursively generate all ways in which an array list can be split up into a sequence of nonempty sublists. For example, if you are given
Recursively generate all ways in which an array list can be split up into a sequence of nonempty sublists. For example, if you are given the array list [1, 7, 2, 9], return the following lists of lists:
[[1], [7], [2], [9]], [[1, 7], [2], [9]], [[1], [7, 2], [9]], [[1, 7, 2], [9]],
[[1], [7], [2, 9]], [[1, 7], [2, 9]], [[1], [7, 2, 9]], [[1, 7, 2, 9]]
Hint: First generate all sublists of the list with the last element removed. The last element can either be a subsequence of length 1, or it can be added to the last subsequence.
Step by Step Solution
3.37 Rating (153 Votes )
There are 3 Steps involved in it
ANSWER def generateSublistsarr if lenarr 0 return else ... View full answer
Get step-by-step solutions from verified subject matter experts
