Write a method increasingSubsequences
that uses recursive backtracking to print every distinct non-decreasing subsequence of a given list.
A subsequence of a list L is a sub-list of two or more elements from L in the same relative order as they were found in L, such that the values in the sub-list are in non-decreasing order.
For example, if a variable called list
stores [2, 1, 5, 8, 8]
, the call of increasingSubsequences(list);
should print the following console output:
[1, 5]
[1, 5, 8]
[1, 5, 8, 8]
[1, 8]
[1, 8, 8]
[2, 5]
[2, 5, 8]
[2, 5, 8, 8]
[2, 8]
[2, 8, 8]
[5, 8]
[5, 8, 8]
[8, 8]
You may print the subsequences in any order.