From 83021c2a63c631d60f7fd535a7d687df4d68ad73 Mon Sep 17 00:00:00 2001 From: Olivia Date: Sat, 1 Apr 2017 14:51:27 -0700 Subject: [PATCH 1/2] Commiting read me for CS-fun recursion tracing assignment --- README.md | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c2e235e..30eca51 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Recursion Problems ## Definitions -Define the following: +Define the following: - Recursion - Recursive Case @@ -23,10 +23,11 @@ def mystery1(n) end end ``` +- What is mystery1(5)? 15 +- What is mystery1(10)? 55 +- What is mystery1(0)? Infinite recursion + -- What is mystery1(5)? -- What is mystery1(10)? -- What is mystery1(0)? ### Trace #2 ``` @@ -37,11 +38,13 @@ def mystery2(n) return (n%10) + mystery2(n/10) end 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 - _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 @@ -60,9 +63,9 @@ def mystery3(n) end ``` -- What is mystery3(1)? -- What is mystery3(13)? -- What is mystery3(-6)? +- What is mystery3(1)? 100 +- What is mystery3(13)? 100 +- What is mystery3(-6)? 200 ### Trace #4 ``` @@ -75,9 +78,11 @@ def mystery4(b,e) end ``` -- What is mystery4(10,2)? -- What is mystery4(4,3)? -- What is mystery4(5,0)? +- What is mystery4(10,2)? 100 +- What is mystery4(4,3)? 64 +- What is mystery4(5,0)? 1 + +I'll keep working at 5 and push that as well. and maybe 6 too. (these are not the easiest for me.) ### Trace #5 ``` From fd1987f65ca4c108bdbd7086df722e442a14777b Mon Sep 17 00:00:00 2001 From: Olivia Date: Sat, 1 Apr 2017 15:31:54 -0700 Subject: [PATCH 2/2] Added definitions --- README.md | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 30eca51..fe5aab0 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,26 @@ ## Definitions Define the following: -- Recursion -- Recursive Case -- Base Case -- Activation Chain/Stack -- Activation Record/Call -- Infinite Recursion/Stack Overflow/Stack too deep -- Tail Recursion +- Recursion - +When a method is called again within the method. + +- Recursive Case - +Any case along the stack within a recursive method that would trigger the internal recursive portion of the method to be called. + +- Base Case - +The case within the method that once satisfied, breaks the loop. + +- Activation Chain/Stack - +The stack of routines activated one after another, say A, then B, then, C. + +- Activation Record/Call - +The history of input calls to the method as the method recurses, keeping track of the progress toward the base case for instance. + +- Infinite Recursion/Stack Overflow/Stack too deep - +The method continues to call itself in an infinite loop adding too much to the stack + +- Tail Recursion - +It's a subroutine call performed as the final action of the method. ## Tracing through a recursive method @@ -44,7 +57,7 @@ end - What is mystery2(123)? 6 - What is mystery2(9005)? 14 -- What is mystery2(-123)? 123 +- What is mystery2(-123)? -123 - _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