So far, everything we’ve done with recursion we could have also done with for loops. The recursive functions that we’ve seen were conceptually somewhat different from the for loop versions, but recursion hasn’t yet given us powers to compute things that we couldn’t compute before. But now it will!
Peptide Fragments
Imagine that we have a set of fragments of proteins, where each fragment has a given mass. For example, the masses of five protein fragments might be [2, 3, 8, 10, 12] in some unit of mass. In addition, we know the mass of the original protein, say 25 units for the sake of example. The question is whether or not there is a subset of our list of fragment masses that add up to the mass of the protein. In this example, the answer is “yes”: fragments with masses 3, 10, and 12 add up to 25. On the other hand, if the fragments had masses [2, 15, 17, 20], we could not have found a subset that adds up to 25. For now, we’re assuming that each mass in the list can be used at most once. This problem arises in the study of protein structure and has been the focus of a recent study.