When do you use in the accusative case? You are accessing the same copy of remaining on every recursion call and it always equal to original and it never hit the condition where remaining.length () == 1. Use len(item, item), i.e. Auxiliary Space: O(m + n), A temporary linked list is needed to store the output number. Time complexity: O( n3 )Auxiliary Space: O(1). Making statements based on opinion; back them up with references or personal experience. Vote for his answer. spring 1233 Questions Count number of Distinct Substring in a String - GeeksforGeeks Print all subsequences of a given string (Recursive approach) We declare a vector of strings to store each sub-sequence as a string. I am wondering is there a better way of coding this? 2 Answers Sorted by: 1 what make this complicated is that you have a double iteration, so one way to attack this making a recursive function for each loop and combine them, this mean a auxiliary function that handle the inner loop and the main one that handle the outer loop. We make use of First and third party cookies to improve our user experience. Once we have generated the corresponding sub-sequence for a binary representation we can push this string into our vector of strings. Expected Time Complexity: O (n*2n) where n is the length of the String To learn more, see our tips on writing great answers. You should pass the remaining string as argument to generateSubsets(remaining) method. 2. substrings_starting_at_first_character (X) = X + substrings_starting_at_first_character (X minus last char). So you should describe why this is different and why it is better. It's in your for loop. Count occurrences of substring X before every occurrence of substring Y in a given string. Enjoy unlimited access on 5500+ Hand Picked Quality Video Courses. Your solution is giving all combinations that can be made using chars in the string Java - using recursion to create all substrings from a string, http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html, joelonsoftware.com/articles/ThePerilsofJavaSchools.html, How a top-ranked engineering school reimagined CS curriculum (Ep. Not the answer you're looking for? In order to generate all the possible pairings, we make use of a function permute (string_1, string_2, current_index). How would you make a list of all the possible substrings in a string using recursion?