-
Notifications
You must be signed in to change notification settings - Fork 30
Allison Northrop - Queues #40
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,15 @@ | ||
| # Recursion Problems | ||
|
|
||
| ## Definitions | ||
| Define the following: | ||
| Define the following: | ||
|
|
||
| - Recursion | ||
| - Recursive Case | ||
| - Base Case | ||
| - Activation Chain/Stack | ||
| - Recursion: Recursion is when you have a method that calls itself. All recursive methods can be written iteratively. | ||
| - Recursive Case: The initial case where there isn't a known number. | ||
| - Base Case: When you finally get to the point where you can input a known number and "work backwards" to get the answer to a recursive problem. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is true. You could also say a base case is the case which stops the recursion by not calling the method again. |
||
| - Activation Chain/Stack: The process in which recursion occurs | ||
| - Activation Record/Call | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is one specific call to the recursive method. |
||
| - Infinite Recursion/Stack Overflow/Stack too deep | ||
| - Tail Recursion | ||
| - Infinite Recursion/Stack Overflow/Stack too deep: When a problem can't be solved/will keep going on recursion forever. | ||
| - Tail Recursion: The last chain of the recursion. | ||
|
|
||
| ## Tracing through a recursive method | ||
|
|
||
|
|
@@ -24,7 +24,7 @@ def mystery1(n) | |
| end | ||
| ``` | ||
|
|
||
| - What is mystery1(5)? | ||
| - What is mystery1(5)? did problems below | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know what this means? I don't see any answers. |
||
| - What is mystery1(10)? | ||
| - What is mystery1(0)? | ||
|
|
||
|
|
@@ -39,9 +39,9 @@ def mystery2(n) | |
| end | ||
| ``` | ||
|
|
||
| - What is mystery2(123)? | ||
| - What is mystery2(9005)? | ||
| - What is mystery2(-123)? | ||
| - What is mystery2(123)? 6 | ||
| - What is mystery2(9005)? 14 | ||
| - What is mystery2(-123)? -123 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These three are correct but are the only answers that I see in this document. |
||
| - _Added Fun: How could we make `mystery2(-123)` work the way we might expect it to work instead of the way it does?_ | ||
|
|
||
| ### Trace #3 | ||
|
|
@@ -61,7 +61,7 @@ end | |
| ``` | ||
|
|
||
| - What is mystery3(1)? | ||
| - What is mystery3(13)? | ||
| - What is mystery3(13)? 100 | ||
| - What is mystery3(-6)? | ||
|
|
||
| ### Trace #4 | ||
|
|
||
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 doesn't make sense to me.
I'd say the recursive case is the case in which the method calls itself.