Recursion has proven to be a very useful programming technique that shortens the length of code drastically. In general the compact form of recursion is very nice to be able to write, however it can sometimes be very confusing and take a while to think through step by step. The best way to judge it is by just going through a case.
For example, with the lab this week the binary notation function we had to create was quite difficult to understand until I went through a case with it, realizing that a base algorithm would work when the binary expression is put back in shorter and shorter.
For example, with the lab this week the binary notation function we had to create was quite difficult to understand until I went through a case with it, realizing that a base algorithm would work when the binary expression is put back in shorter and shorter.
Thinking about the base case first really helps for me. Then I think about what operation is being repeated over and over again.
ReplyDeleteYep! As Danny said in one of his last slides we as humans have that advantage when compared to computers, really would've helped to come to that realization more quickly in the Anne's Stools project when I spent hours trying to figure out the recursion for that,
ReplyDelete