About the 2008 6.00 OCW, in problem set 3 (Q1), how do I count the number of instances of the key in the target string using recursion?
MIT 6.00 Intro Computer Science (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
Generally, a recursive function has three parts.
The "base case", which is when to stop calling the function, in this case when the end of the string is reached.
Code for what you want to do as you're recursing. Before the base case is reached, and more recursion needs to be done.
Code for what you want to do as the recursion "unwinds". After the base case is reached and the recursions are returning.
Thinking recursively is tough to get used to, but well worth the effort.
@rsmith6559: Well, I do know the logical steps of recursion; I'm unsure of how to count the no. of recursions that occur. Thanks anyway.
The base case returns 0, and the others increment it before returning it.