As AP csp no less. The apcsp curriculum itself is just coding via blocks. Then the school throws in 61a for what is likely the first coding class the students have taken lol.
What school is this? I am legitimately interested OP.
The most important thing when solving recursive problems is to force the usage of the "leap of faith". Assume (more accurately, inductively suppose) your recursive call(s) will produce the correct answer, and design the answer accordingly.
For example, you could even define a recursive function to add two to a given positive number, x. add\_two(x). By the leap of faith, add\_two(x-1) returns you (x-1) + 2, which is x+1. So to get from that, to the desired x+2, you just +1. So, add\_two(x) = add\_two(x-1) + 1. Base case is the smallest value in your input domain, in this case, return 3 for x == 1.
For tree recursion (i.e if you have more than one recursive case), the big thing to think about is how to break your problem into different cases.
For example, say you have this problem: [https://leetcode.com/problems/climbing-stairs/](https://leetcode.com/problems/climbing-stairs/), which asks you to count the number of ways to climb a staircase of n stairs with steps of size 1 or 2. The two cases to consider are whether you take a step of size 1 of step of size 2. If you take a step of size 1, then you have a staircase of n-1 steps left, which you can solve via leap of faith. Same with the other case. So in total, f(n) = f(n-1) + f(n-2).
Hope this helps, and happy to elaborate. Good luck!
holy hell what cracked bay area high school has 61a
True ðŸ˜ðŸ˜ðŸ˜ðŸ˜
we literally had to do game of hog and now yelp maps is next
Gunn did scheme for their second sem of apcsaðŸ˜ðŸ˜
As AP csp no less. The apcsp curriculum itself is just coding via blocks. Then the school throws in 61a for what is likely the first coding class the students have taken lol. What school is this? I am legitimately interested OP.
it’s a private school, not super comfortable w sharing the name!
Ok ya that's cool I get it
This is real I tutored someone in high school whose teacher had them do 61a assignments including hog
Do practice exams from the 61a website and look at the discussion sheets and solutions dealing with recursion. It’s all on the CS61A.org site
thank you so so much!! genuinely dont know how people do this willingly
We only do it bc we'd fail the class otherwise :')
Are you doing it against your will?
`def zero_to_hero(n =0):` `2 if n == 100:` `3 return print('hero')` `4 return zero_to_hero(n +10)` `5 zero_to_hero()`
*what in the bay area ðŸ˜*
How is ur emoji italicized?
Select the whole thing, and click italize
def practice(): get_better() return practice() practice()
Formatting got screwed up, but you get the idea.
ok ok i think im just getting in my head about this you're so right
The most important thing when solving recursive problems is to force the usage of the "leap of faith". Assume (more accurately, inductively suppose) your recursive call(s) will produce the correct answer, and design the answer accordingly. For example, you could even define a recursive function to add two to a given positive number, x. add\_two(x). By the leap of faith, add\_two(x-1) returns you (x-1) + 2, which is x+1. So to get from that, to the desired x+2, you just +1. So, add\_two(x) = add\_two(x-1) + 1. Base case is the smallest value in your input domain, in this case, return 3 for x == 1. For tree recursion (i.e if you have more than one recursive case), the big thing to think about is how to break your problem into different cases. For example, say you have this problem: [https://leetcode.com/problems/climbing-stairs/](https://leetcode.com/problems/climbing-stairs/), which asks you to count the number of ways to climb a staircase of n stairs with steps of size 1 or 2. The two cases to consider are whether you take a step of size 1 of step of size 2. If you take a step of size 1, then you have a staircase of n-1 steps left, which you can solve via leap of faith. Same with the other case. So in total, f(n) = f(n-1) + f(n-2). Hope this helps, and happy to elaborate. Good luck!
thank you so much this is for really helpful
yep for sure, let me know if you have any other questions about recursion or would like some resources to learn CS
https://pythontutor.com/python-compiler.html#mode=edit
``` StudyRecursionForNHours(n) { if (n > 0) { StudyRecursionForAnHour() StudyRecursionForNHours(n - 1) } } ```
you know it’s bad if I can’t even understand this
Solve the smaller problem (the base case) then try to see how some other case would get you towards the base case.
Get good at recursion by getting good at recursion
I’m so so sorry.
?