How to Think Recursively - Part 2

Please read How to Think Recursively before reading this post. This post re-applies the steps mentioned in the previous post on a more challenging question. Question Return all possible ways we can generate a well-formed parenthesis? Examples: if n = 1 then we can only form () if n = 2 then we can form (()) and ()() if n = 3 then we can form ((())), (())(), ()(()), (()()), (), (), () Let’s try applying our 4 steps:...

November 15, 2022 Β· 5 min

How to Think Recursively - Part 1

These articles are about the gotchas I faced when trying to think recursively. The logic in principle should apply to most recursive problems. In this post, I will use the following question as a point of reference: Count how many ways you can climb a staircase. You can jump either one step at a time or two steps at a time. Example if there are 3 stair cases then you can either jump:...

November 15, 2022 Β· 9 min