From c9cd449990fd213f82a50cae46b4f1600fb0ad8f Mon Sep 17 00:00:00 2001 From: Marisol Lopez Date: Sat, 8 Apr 2017 22:02:05 -0700 Subject: [PATCH 1/2] added answers for traces 1 - 5 --- README.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index c2e235e..2bb41ac 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Recursion Problems ## Definitions -Define the following: +Define the following: - Recursion - Recursive Case @@ -24,9 +24,9 @@ def mystery1(n) end ``` -- What is mystery1(5)? -- What is mystery1(10)? -- What is mystery1(0)? +-What is mystery1(5) = 15 +-What is mystery1(10) = 55 +-What is mystery1(0) = Infinite Recursion ### Trace #2 ``` @@ -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 - _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 +60,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 +75,9 @@ 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 ### Trace #5 ``` @@ -90,9 +90,9 @@ def mystery5(s) end ``` -- What is mystery5("hi")? -- What is mystery5("")? -- What is mystery5("Hi, there!")? +-What is mystery5("hi") = "**" +-What is mystery5("") = "" +-What is mystery5("Hi, there!") = "**********" - _Added Fun: How could we make only alphabetic characters to be changed to stars?_ ### Trace #6 From add4571a03f69550d2f859e9aecb0a3613f3155f Mon Sep 17 00:00:00 2001 From: Marisol Lopez Date: Sat, 8 Apr 2017 22:14:11 -0700 Subject: [PATCH 2/2] added definitions exept activiation record/call --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2bb41ac..83e69c5 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,13 @@ ## Definitions Define the following: -- Recursion -- Recursive Case -- Base Case -- Activation Chain/Stack +- Recursion: Describes when we have a method that calls itself. +- Recursive Case: A part of the method that happens over and over again. +- Base Case: The situation for which the solution can be states non-recursively. +- Activation Chain/Stack: The chain that results when going through recursive method. - Activation Record/Call -- Infinite Recursion/Stack Overflow/Stack too deep -- Tail Recursion +- Infinite Recursion/Stack Overflow/Stack too deep: When a method will never stop because it will never satisfy method. +- Tail Recursion: Recursive call is the last thing executed by the function ## Tracing through a recursive method