Professional Documents
Culture Documents
2x Courseware | edX
/**
* @param word consisting only of letters A-Z or a-z
* @return all subsequences of word, separated by commas,
* where a subsequence is a string of letters found in word
* in the same order that they appear in word.
*/
public static String subsequences(String word)
This problem lends itself to an elegant recursive decomposition. Take the rst letter of
the word. We can form one set of subsequences that include that letter, and another
set of subsequences that exclude that letter, and those two sets completely cover the
set of possible subsequences.
https://courses.edx.org/courses/course-v1:MITx+6.005.2x+1T2017/courseware/Readings/01-Recursion/?activate_block_id=block-v1%3AMITx%2B6.0… 1/3
5/10/2020 Choosing the Right Decomposition for a Problem | Reading 1: Recursion | 6.005.2x Courseware | edX
reverse result
7
Why does the example give me the string reverted? subsequences("abc") returns with ",a,b,ab,c,a…
https://courses.edx.org/courses/course-v1:MITx+6.005.2x+1T2017/courseware/Readings/01-Recursion/?activate_block_id=block-v1%3AMITx%2B6.0… 2/3
5/10/2020 Choosing the Right Decomposition for a Problem | Reading 1: Recursion | 6.005.2x Courseware | edX
subsequenceOfRest.split(",", -1)
4
Why '-1' has been used as a parameter of split() function? I am not clear. Please explain it.
https://courses.edx.org/courses/course-v1:MITx+6.005.2x+1T2017/courseware/Readings/01-Recursion/?activate_block_id=block-v1%3AMITx%2B6.0… 3/3