-
Notifications
You must be signed in to change notification settings - Fork 30
Queues - Ting Wong - Recursion Tracing #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| This means that the recursion is calling itself infinitely and a solution can't be reached (or that no solution is possible). | ||
|
|
||
| - Tail Recursion | ||
| I think that tail recursion means that rather than performing all your recursion calls first before returning back to calculate the results, you first perform all your calculations then move to the next recursive step. In this way, some efficiency is gained as you don't need to go through the activation chain all over again to perform the recursion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't go over this in class, but this is mostly right. I may cover in the future, but it's not terribly important at this moment.
| else | ||
| return (n%10) + mystery2(n/10) | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... This will definitely change the behavior of what the method does, but perhaps I should have specified what "the way we might expect it to work" is. I wold expect mystery2(-123) to produce -6 not 6. If you expected 6, then your solution is correct. If you wanted -6, then it's not.
| end | ||
| end | ||
| end | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job! A couplet things to consider here.
-
Regex would make this potentially a more sophisticated solution, but yours is maybe easier to read.
-
Is your assumption that we would want to strip out all non-alpha characters? That's what your solution would produce ==> mystery5("Hi, there!") would be "*******", but what if we wanted it to be "**, *****!" which is what I intended. I will make these instructions more clear for my next iteration of this assignment.
Recursion TracingLooks good! |
Recursion Tracing
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions