2016年3月30日星期三

Week 11


I revisited, week 7 slog, I found that I have changed some of my views and developed in some way. I still think that Recursion is important, useful, and can help us to solve a problem easily. But now, I do not feel difficult, because I put a lot of effort on it, I did every question on the lab and lecture PPT, then I realized nothing is hard unless you do nothing. Also, I found any recursive algorithm can be converted non recursive form. But, for me, I think recursion is easier. Now, I found that recursion can be used on trees and it is very important. We can use recursion to find a thing that we want in a tree, either normal tree or binary tree or even a binary search tree. We can delete it or change it or move it. In the future, we can use it to save information for us, and get information is a tree for us. Anyways, Recursion is everywhere in computer science, it is much more important than I thought in week 7. And I have an advice to my classmates if you want to do well in computer science, you have to master recursion, you have to do a lot of practice.

WEEK10

we learned efficiency of algorithms this week,this section is very hard for me ,because it is not teaching you how to implement, it is teaching you how to find run time of a function or program. I learned two types of run time . first one is n and second one is nlogn ,as the n becoming larger, the second one nlogn will be much more smaller than the first one. When we implement a function, we should try to use nlogn algorithms, it will make the function faster and less memory require

2016年3月23日星期三

SLOG WEEK9

This week, we learned binary tree and binary search tree, two trees are very similar, also very "different". They all have two children maximum, but in binary search tree, the value of left child must smaller than parent,and value of right child must bigger than parent. In binary tree,we do not care this. Also ,I was confused about preorder, inorder, and postorder, then I found some pattern, it help me to remember these three order.Also, in binary tree, we still use a lot of recursion. I also understand that binary search tree can be used to save informations, anyway, we have not learn this yet.

SLOG WEEK8

Tree, is a abstract data type, a tree has the head(root), and children, and parent, and height,etc. tree is different from binary tree. a parent can have many many children, but binary tree can only have two children. when we implement a tree method, we will use recursion usually. We implemented few method in the lad and class, such as count_height,count_leaf,etc. But I always confused about those terminologies, and I will try to understand those terminologies deeply, because it is very important in computer science.

2016年3月2日星期三

SLOG WEEK7

Recently, we have learned something called recursion. Recursion is very important in computer programming, and it is very useful. Sometimes, it can solve the problem easier than not using recursion. I have never seen this word before, thus I feel a little bit difficult. In computer science, recursion is a method that divides a big problem into several small problems. The lecturer said that recursion must call itself in the function text, otherwise, it is not recursion. Therefore, when I am dealing with recursion, I have to think how do I call it in itself, and make it like a “loop”, maybe it is not an accurate word to describe recursion, but I cannot find another word to replace it.
"The power of recursion evidently lies in the possibility of defining an infinite set of objects by a finite statement. In the same manner, an infinite number of computations can be described by a finite recursive program, even if this program contains no explicit repetitions."(Wirth, Niklaus (1976). Algorithms + Data Structures = Programs. Prentice-Hall. p. 126.)
This is a very accurate description by Wirth, Niklaus. For example, Fibonacci sequence. The following codes are doing Fibonacci sequence with and without recursion.
def F(n):
                              if n == 0: return 0
                              elif n == 1: return 1
                              else: return F(n-1)+F(n-2)
                          def F(n):
                              a=1
                             b=1
                              temp=int()
                             for i in range(1,int(n)-1):
                                temp = a+b
                                a=b
                                b=temp
                             return b
From the codes, we can see that recursion can be simpler than not using recursion. In the first version, we just like peeling a fruit. Finally, we will get the core. Another method is more complicated. When we do a more complicated question, we might make mistakes without using recursion and the mistake is very hard to find in many codes. When I was doing the exercise, I found that there is a mistake that people always make, the function call itself infinite times and python give “maximum recursion depth exceeded” error to you. We need to be careful.