Grading Criteria

  • 1/1: No missed MC + code showing recursion
  • 0.95/1: Missed 1-2 MC questions + had code showing recursion
  • 0.90/1: Missed 1-2 MC questions + no code showing recursion
  • Late submission:
    • 0.05 deducted

Scores

Names Score
Bailey Say, Andrew Meng, Aarav Arora, Nicholas Mounier, Rohan Juneja 1/1 full score on MC + good implementation of recursion in code
Kian Pasokhi 1/1 full score on MC + good implementation of recursion in code
Everitt, Samuel, Kinish, Ritvik 1/1 full score on MC + good implementation of recursion in code
Bria Gilliam, Shraddha Kadaba, Evan Sanchez, Calissa Tyrrell 1/1 full score on MC + good implementation of recursion in code
Iris 1/1 full score on MC + good implementation of recursion in code
Evan Yang, Karthik V, Sanjay B, Pranav S, Jay M. 0.95/1 missed one MC question + good implementation of recursion in code
Linda Liu 1/1 missed one MC question + good implementation of recursion in code
Lily Wu, William Wu, Vidhi Kulkarni, Riya Patil, Saathvika Ajith 0.95/1 missed one MC question + good implementation of recursion in code
Sahil, Rohit, Nathan, Kurtis 0.95/1 missed one MC question + good implementation of recursion in code
Serafina Wong 0.95/1 missed one MC question + good implementation of recursion in code
Prisha Boreddy 1/1 full score on MC + good implementation of recursion in code
Divyanshi Suri 0.85/1 missed one MC and submitted late
Re'em, Gabe, Soren, Avinh 0.95/1 Full score on MC + good implementation of recursion in code + submitted late

MC Explanations

  1. In the first function call, 2 + dosomething(2,2). In the second call, 2+2+ dosomething (2,1). Then, base condition is met: 2+2+2 = 6

  2. Ternary operator is basically a compressed if else statement, which has the format (condition) ? (Do this part after question mark if condition is true) : (do this part after colon if condition is false) and returns whichever value) So reading the statement on Line 2, it says that if num is true (aka not 0), return the module and repeat with recursive call to itself divided by 10. Otherwise, return 0. The key is that dividing by 10 is basically like stripping off the last digit, because it gets truncated (ex. 19/10=1.9 which gets rounded down to 1, so it essentially just removes the 9 by moving it behind the decimal point). So what the ternary operator is doing is adding the last digit, then stripping off the last digit, and adding THAT digit, … Essentially taking the sum of all the individual digits. So the answer rec(4567) is just 4+5+6+7 = 22

  3. Recursion uses more memory than iteration because in recursion, each function call is stored in a call stack.

  4. Recursion can be written as loops - therefore, most similar to loops. See presentation.

  5. Base case is when the recursive method is stopped and a value is returned.

  6. The answer is 24. The recursive method will terminate when either b <= 1 or b <= a. In these two cases, it will return 1. Do traces of the calls:

    foo(5,9) = (9-5) foo(5,8) = 4 foo(5,8)

    foo(5,8) = (8-5) foo(5,7) = 3 foo(5,7)

    foo(5,7) = (7-5) foo(5,6) = 2 foo(5,6)

    foo(5,6) = (6-5) foo(5,5) = 1 foo(5,5)

    foo(5,5) = 1

    Therefore, carefully tracing back up, we get: foo(5,9) = 4 3 2 1 1 = 24

  7. The number 10 is inputed into recurs and prints count, subtracts two from count, then reentered into recurs. First iteration gives 10. The second iteration gives as, 10, 8. It places 8 after the value from the first iteration. Repeating this, we get 10 8 6 4 2. When count reaches 0, nothing is printed.

  8. Fibonacci is an example of iteration. Think back to Trimester 1.

  9. A recursive method calls itself within the method.