Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

pset3 problem1. sos. i can't make recursive one can anybody give me some hint please?

MIT 6.00 Intro Computer Science (OCW)
See more answers at
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.

Join Brainly to access

this expert answer


To see the expert answer you'll need to create a free account at Brainly

oh i just have got an answer!
1 Attachment
The two functions should return the number of occurrences of key in target. You can check my version here: I also joined two diagrams to help you visualize the code. Let's review first the code of your iterative version. My first objection is that you always return None, even if you print occurrences when you find them. You should have a variable which counts how many times you find the key. Now you iterate over the target, starting with position 0, if you find the key at position n, increment your counter and search again starting at position n+1. As soon as you don't find the key, return the number of occurrences you have found. Now let's look at the recursive version. You did pretty well and almost found the answer, since you call the same function with a shorter target (hence it is a simplified version of the same problem). You should only ask yourself: what do I want to return when I don't find the key -> you should return 0. And when I find the key? -> 1 + return from the shorter target. I hope I made it clear, but let me know if it is not enough !
very helpful advice! thank you!

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

maitre_kao. nice job. elegant. i like the way you increment directly in the return statement.
here is another variation
bwCA. very cool and concise. didn't know about "not in"

Not the answer you are looking for?

Search for more explanations.

Ask your own question