Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Recursion works when you can break solving a big problem down to solving a smaller version of the same problem. So, like, if you want to balance a heap, you can start at the root node, and call "balance" on the left heap and right heap.

So, each step needs to get you closer to the goal, working on a smaller problem, until you reach a base case, a really small problem that you don't solve in terms of recursion. You check for the base case, a really small problem you actually solve directly instead of handing it off to another recursive call, and you actually return your solution to the caller.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: