Second thing I learned from this chapter is unwinding. Unwinding is expending or rewriting a recursive algorithm until it can be expressed as a closed form. Usually, the unwinding happens until number of steps reach the size of the input, n. The algorithm is usually simplified to a closed form, an expression in finite number rather than a recursive algorithm. When I tried the unwinding the first time, I kept expending until I found a pattern. However, this was a mistake. It is much crucial to expend to a a simplified form. For example, unwinding a Fibonacci sequence can generate a pattern of pascal's triangle;
F(n) = F(n-1) + F(n-2)
= F(n-2) + 2F(n-3) + F(n-4)
= F(n-3) + 3F(n-4) + 3F(n-5) + F(n-6)
....
It is true that there is a pattern but the pattern can hardly be implied to a closed form. Therefore, the following unwinding would be much easier to handle closed form;
F(n) = F(n-1) + F(n-2)
= 2F(n-2) + F(n-3)
= 3F(n-3) + 2F(n-4)
= 5F(n-4) + 3F(n-5)
....
At nth step, the first unwinding is so huge that it would be hard to compute. On the other hand, the 2nd unwinding has just two terms so it is much easier.
From this, I learn that sometimes finding a pattern is not really it. I have to think if this can be implied to a closed form. If it is impossible, I have to go back and find another pattern.
No comments:
Post a Comment