2014年3月30日星期日

Week #11: Sorting and efficiency

Over the last serveral weeks, we learned about the sorting and efficiency from the lecture, reading resource, and lab practicing. Sorting is a method which can collect the elements in a specific order in computer science. However, there are many different kinds of sorting method in python, such as bubble sort, selection sort, etc. Based on my comprehension, we are not going to learn about how to write the sorting function instead of learning that which sorting method is more efficiency and why this method is more efficiency than other. This is the purpose of what we learned about in this week.

When I studied the sorting and efficiency, I would like to realize the process of executing firstly in the bubble sort, the selection sort, the insertion sort, the merge sort and the quick sort. In this week's lab exercise, we did a experiment about the sorting efficiency and abserved the change of result in different condition. When we know about the execution of different sorting method, we will understand the experimental result more easily. 

In the lab, after we collected the data of sorting time, we made some graph in excel for observing the change of the result and discuss with my partner. We found that, the data just changed slightly and the selection sort is the most efficiency in this condition.

After finishing the lab and lecture, I found that the most important reason of sorting efficiency is that if the sorting function is more complex, it will spend more time. Also, the input will affect the running time. We can do the exercise of big-oh for improve the knowledge of sorting efficiency.

2014年3月16日星期日

week #8 --- Tree

This week, we learned about the Tree class. Based on this class, there were many methods and it extended some knowledge points. For example, recursion and subclass.

The tree list must have three element. The first element is root and the rest are their leaves. The leaves can be a new tree list and also can be None. Basically, we can do a lot of exercise about tree by ourselves. It seems like our exercise 3. We know the preorder and inorder tree list, and return the original tree list. After that, we wrote one more function about count the sum of deepest leaves from root for the tree list. For this kind of exercise, we can understand and apply recursion and writing the helper function inside the main function deeply.

For the computer science, every day we learn the different knowledge and every day we think the different methods for the function. We need to keep practicing everyday and improve our knowledge well. 

2014年3月1日星期六

Week #7 --- Recursion

In the last few weeks, we learn about the recursion deeply from lectures, reading materials, labs and assignment 1. Base on my comprehension, recursion means we call the function inside itself for solving the subproblem easily. The recursion makes the function always run and stop until finding the result of subproblem.

When I knew recursion in the lecture first time, I had no ideas for this term, because it seemed very abstract and hard to understand. After reading the material from the course website, though I knew what is the recursion, I still did not know how to apply recursion in python so that I felt difficult to finish the lab exercise in the lab. Talking about the lab, I was really appreciated to my partner since he helped me lot. He told me a method for understanding recursion easily. When I get a question, I will seperate the question into two parts. The first part is basecase which means the normal case. The second part is recusion case. I want to use an example to explain what is basecase and recursion case.

For example(This is an example from the week 5's lecture):
def rec_max(L: list) -> float:
    """Return the max number in possibly nested list of numbers.

    >>> rec_max([17, 21 0])
    21
    >>> rec_max([17, [21, 24], 0])
    24
    >>> rec_max([17, [21, 24], [18, 37, 16], 0])
    37
    """

    return max([rec_max(x) if isinstance(x, list) else x for x in L])

In this case, the basecase is when L is a normal case and L do not contain any nested list. The rec_max function will only run once time. Therefore "else x" is basecase. When L contains some nested list, we need to run rec_max function in the nested list . This case is recursion case. Therefore, we write the recursion case "rec_max(x) if isinstance (x, list)". When x is nested list, we need to call the rec_max function again. This is what recursion means. However, "for x in L" is the condition of the function which can make the function stop when every element in L executed. This method is my partner teaching me which is a good method for me to solve the recursion problem. 

In the assignment 1, we did a good application of recursion. We use recursion to finish the 4-stools hanoi tower game. This is the first assignment of CSC148. I think the most difficult part is part 5 --- calculate the minimum moves of 4-stools cheeses. This is a kind of recursion problem. I spent almost two days finishing part 5 of this assignment with my partners. We discussed together, search some reading source from internet. We seperated the problem into two small parts. First, we though about the minimum of cheeses move in 4-stools. Then, we write the code for the number of moves. Finally, we combined two small parts in the main code. During the process, we got a lot of error. We modified the code continuously until we pass the testcase. When we finished the recursion of part 5, we were screaming at that moment. We were excited we can overcome the challenge. After I finished the assignment 1, my biggest experience is that the most difficult part is recursion and we achieve a good application of recursion this time. 

Although we practiced a lot about recursion in the lab, assignment 1 and term test 1. I think we still need to practice more different recursion problem for comprehencing recursion more deeply in the further study. 

2014年2月8日星期六

Week 5(Feb.3 - 7)

In this week's lecture, we were talking about the application of Tower of Hanoi in Python. Also, we learned about scopes and namespaces. I believe that most of people are familiar with this game. Base on this reason, when we were talking about completing the code of Hanoi during the class, we were easy to understand the change of source, intermediate and destination.

In the lab, we also practiced the problem of recursion. I think this lab was more challenge than previous lab, because I cannot finish all the tasks with my partner ontime. I tried to ask TA for help, but I think we do not understand the recursion clearly enough. I will do more practice about recursion this week for a good preparation of Assignment 1.

2014年2月2日星期日

Week - 4(Jan.27-31)

This week, we learned about inheritance and the basic of recursion. Firstly, I want to talk about inheritance. As far as I know, inheritance makes a subclass for a superclass. We applied this method to this week's lab and exercise. I figure it out with my partner in the lab. For example, class Motorized(Car) and class Bicycle(Motorized), then Bicycle also inherit the method of Car. With the process of learning CS, I found that it is useful for us to read the website's source before the class and communicate more with partner about the problem after class. 

Then, we also learn a little basic about recursion which is a kind of method to solve problem. Recursion will break down the problems into many smaller parts which they are small enough to solve easily. Although I know the what is recursion, I do not practice the problem of recursion. Therefore, I am not sure I can do well in recursion problem. Next week, I will do more practice about recursion for understanding more.

Although learning CS is very hard and stressful, I believe that if we do more practice, we will learn more. I will keep practicing every week. I hope I can get a good result of this course.

2014年1月23日星期四

Week 3: Object-Oriented Programming (Jan.20 - 24)

Object-Oriented Programming is one of an advanced programming languague. When I saw this terms 'Object-Oriented Programming' in the first class, I was really confused about it, because I cannot find the difference between what we learned from CSC108 in the fall term. Fortunately, I found some sources about OOP from the course website. Also, I read the Piazza for finding the appropriate ideas and solution. In this process, I knew another term of programming languague which is procedural programming and it is the similar method which we write the program in CSC108. This programming language focuses more on writing functions and procedures for operating on data; However, OOP focuses more on the creation of objects which contain data and function. Comparing to procedural programming, OOP is a more efficient method to solve the problem in computer science. When we use this programming language, the data and function are stored by created objects. These objects are able to achive to store the data and execute the function. When we work for multiple problems with OOP, it is useful for us to solve problems with esay modification.