These can be solved using:

The idea is to consider two cases for every character.

  1. Consider current character as part of the current subset
  2. Do not consider current character as part of the current subset.

Let us understand the recursion with an example “abc”. Every node in the below tree represents the string curr.

At root, index = 0.
At next level of tree index = 1
At third level, index = 2
At fourth level index = 3 (becomes equal to string length), so we print the subset.

Problem code is available here Lexicographically sorted power Set