recursion below recursion code example

Example 1: recursion

# modified code tranclated to python from (Drab Duck)

def fact(num):
  if num <= 1:
      return 1
  else:
    return num*fact(num-1)

Example 2: Recursion

/**
 * Return all subsequences of word (as defined above) separated by commas,
 * with partialSubsequence prepended to each one.
 */
private static String subsequencesAfter(String partialSubsequence, String word) {
    if (word.isEmpty()) {
        // base case
        return partialSubsequence;
    } else {
        // recursive step
        return subsequencesAfter(partialSubsequence, word.substring(1))
             + ","
             + subsequencesAfter(partialSubsequence + word.charAt(0), word.substring(1));
    }
}