Problem 2: Write a recursive algorithm that finds all occurrences of a substring in a string.

Sample Input:
- Each line contains a string followed by a comma, then a substring.
- "atomic data", "at"
- "ed edd n eddy", "ed"

Sample Output:
- 0, 8
- 0, 3, 9

Answer :

Here's a recursive algorithm that finds all occurrences of a substring in a string using the sample input and output you provided:

SubstringOccurrences (string, substring, index+1, result)ElsefindSubstringOccurrences (string, substring, index+1, result)return result To explain, the algorithm takes four parameters: the string to search for the substring in, the substring to search for, the current index (initialized to 0), and a result array that stores the indices of the occurrences of the substring in the string.

The algorithm first checks if the current index is less than the length of the string. If it is, it checks if the substring is present starting from the current index using the substr method. If it is, it adds the current index to the result array and recursively calls the function with the next index. If it is not, it simply recursively calls the function with the next index. Once the current index reaches the length of the string, the function returns the result array.

To know more about recursive algorithm visit :

https://brainly.com/question/32899499

#SPJ11