This week, we talked about more recursion examples. In this examples, I have learned how to trace the recursion and understand the code of recursion functions. Especially, I learned how to make the function more efficient by using dictionaries in the recursion.
Recursion is an easy way to handle some problems that look complicated but sometimes it will wast some time to operate. In our reading, it will take a lot of time to cope with the problem of Fibonacci numbers. The code is like:
However, the reading material also tells us how to handle it by dictionaries, we can simply create a dictionary to record what we have already gotten:
It is amazing and really helpful in my programming the assignment 1. Now, I can effectively accelerate my program by this technique. I find that we need to avoid not only duplicate codes but also allowing the computer to do duplicate tasks in programming. I have noticed that how important and helpful the efficiency is. I know we will cover more about efficiency in the future so this is a good beginning for myself.
After I spent two nights and a few hours in the day, I have successfully achieved the entire tasks of the assignment 1. The most difficult point is processing Tour.py which lets the computer itself to finish the Hanoi problem. It's a long way to encode, debug, mortify the documentation and optimize it. Nevertheless, I really enjoy this process and felt excited when the computer perfectly did what I asked!
No comments:
Post a Comment