logo CodeStepByStep logo

increasingSubsequences

Language/Type: Java recursion recursive backtracking
Related Links:

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.

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.