2015年3月30日星期一

Looking back at earlier posts (Writing for Week 11)



  For this week, I decided to look back my posts about class and recursion. I have to say, I was too naive at the very first place.


__________________________________Part 1Class_______________________________
  I thought that class was complex and useless, because we could wrote everything and everything could work quite well without class. So why do we bother class? It seems that class made things even more complicated. However I was totally wrong.
  The function of "class" is similar with that of categories. Without it, everyone would feel helpless facing a mass of codes. "Class" help us organize or thoughts logically and make our codes readable. We could imagine classes and subclasses as a tree, for example, some classes might have children which are subclasses, and subclasses could inherit everything from their parent and grow their own leaves that are their own characteristics.
  To be specific, class is the trunk or the main branch, which means class could be generous. This makes "hierarchy" possible. Superclass is the parent/leader of other subclasses, every subclass has its own duty and job. You could see the functions of a superclass, but those functions could be used only in subclass. These are the jobs, or we could say the "sub-jobs" of the class.
  Those clearly defined and separate jobs make things easier for programmers and readers to handle. What's more important, if you want to change something in your code according to your clients' requirements, you do not need to change your whole work since other unrelated variables wouldn't be affected by those changes. Why?  Because you separate each function as an independent unit with the help of subclass.

_______________________________Part 2● Recursion_____________________________
  As for recursion, I agree with most of what I said. I really appreciate that we are taught firstly about tracing recursive functions as a way easing us to learn how recursive functions work. Recursion is not simple for me even now. For the most of the time of learning CSC148, I was struggling with recursion. Nevertheless, the more I think, the more useful and elegant recursion is.
  I thought for loop and while loop are much easier, and I still believe they are easy, however, in my opinion, they are only easy to "figure out" and cannot work complex problems easily and well. For recursion, the most difficult part is working out how this recursive function supposed to work, then writing down correspond codes. And I believe, only through practicing can we handle recursion better.


   Looking back at what I've learnt, I'm surprised. We've learnt so much amazing and elegant things in such a short time, though there're still something I have trouble with. The most important thing is, I feel I'm learning more knowledge about computer science and the way that we're supposed to think while programming also help me in other areas.

Impressions for week 9 (writing for week 10)

  This week we learn more about insert and delete functions of BST. It seems the extension of the last few weeks' lecture, so I read some articles and books about BST in order to get a better understanding.
  Also, there was a test this week, which I didn't do well. I forget to review Linked List, so...the last question was a almost a disaster for me... My friends said they took the advantages of "cheating sheet", so the test was quite easy for them. Although we were allowed to take cheating sheet, but I don't want to, because I always feel confidence about what I know and its accuracy. Fine..This test taught me try to understand everything everyday, never leave any questions.

2015年3月26日星期四

Impressions of week 8 (writing for week 9)


  This week we learn a lot about linked list. Linked lists can keep elements in a certain order in a very different style. "A linked list, relies on a more distributed representation in which a lightweight object, known as a node, is allocated for each element. "  I think linked lists are the combination of trees and lists. The main difference between linked lists and trees is that every linked-lists node only have one child that refers to the next node or the tail, resulting in a straight line of data, which looks like a list.

  Important knowledge in week 7






  


  A. Head and Tail

  As we see in the picture above, the first and last node of a linked list are known as the head and tail of the list respectively. Following the each node's next reference, we move from one node to another, starting at the head. Finally we reach the tail of the list. We could say that the tail as the node having None as its next reference.

  


  B. Nodes

  Remember that each node is a unique object.

  C. LLNode Class and LinkedList Class

  It was kind hard for me to understand how those nodes are stored in a "list". Is that really a list or there exists another form. And it was not easy for me to shift or insert nodes. Then I thought it would be easier if I imagined that it is a list and the elements of the list are nodes, however, all of those nodes contain two parts. One part is "themselves" which means the object, such as a number, stored in a instance variable called "element", and the other part is a pointer which refers to the next "element". just forget about the form that they are stored.

  D. The disadvantages and advantages of linked lists

  Elements of a linked list cannot be efficiently accessed by a numeric index and we cannot tell just by examining a node if it is the second, third or something else in the list. However, being different from binary trees, linked list provide us a chance to store a sequence in a specific order.


  Throughout the lecture for this week, we learned how to insert, delete and using recursion with linked lists. I can't wait to learn more practical using of linked lists!

Impressions of week 7 (writing for week 8)


  Coming back from reading week!

   This week is all about Assignment2

    It was a NIGHTMARE! 

    The due date of assignment2 is coming.... And the assignment is absolutely becoming tougher! My team spent hours working on that, but nothing came out. Although, professor talked a lot about how to find ways to solve problems in assignment2, I still didn't know what they're talking about. I had no idea what to write until I read lots of articles about recursion and class.
  I believe the most difficult part is that you have to figure out all the functions by yourself. For example, you need to think about what kind of methods you need and what kind of methods can make things easier and can make the codes work efficiently.
  At first, I wanted to write the new game at the beginning, because I thought it was easier if I could link things in the game and minimax together. However, I was totally wrong. Since Minimax is extremely general, which means it could be executed in every game. So why not write Minimax first and then figure out the connections between Minimax and the new game? Then we started to writing Minimax and things got better!
  The main part of the new game is about judging "tie", "win" and "lose". And this is the part that I took responsibility for. At the beginning, my team members decided to use tuple to represent the positions of the net. Things looked quite well until I wrote method winner. That was horrible. Using tuple as coordinate made things even worse. I always thought that "in order to build the connection between Minimax and winner, I should use proper numbers to represent those positions" and I was proved right latter, however, at that moment, I believed that "the numbers representing the positions are used to subtract". So how to choose proper numbers became a HUGE problem for me and I found out it couldn't be solved at all!! Then I made up my mind to change a bunch of previous codes...Eventually I realized that those numbers have nothing to do with Minimax essentially....
  After fighting with codes for nights, we finally finished this assignment! However, it took more than 10 minutes to figure out which is the best position for computer itself even in 3 x 3 nets...



Summary of Recursion (For week 7)


  I've talked a lot about recursion in my previous posts, but I never wrote something dedicate directly to recursion. And also, I believe Recursion is the one of the important cores of the whole course, which is the reason why I choose to summarize recursion.

_________________________________________________________________________________

  One way to describe repetition within a computer program is the use of loops, such as while-loop and for-loop constructs. Recursion is an entirely different and new way to achieve repetition.
  First of all, I'd like to talk about what is recursion.  Recursion is a technique "by which a function makes one or more calls to itself during execution, or by which a data structure relies upon smaller instances of the very same type of structure in its representation.[1]" Recursion provides an elegant and powerful alternative for performing repetition tasks.  So secondly, I want to talk about the fundamental pattern of writing recursive functions:


         ●Step 1 Setting a general and easiest base case which does not need recursion. For example, for the most of the time, in a tree, the first step is assuming that the tree has only one node(which is also the root).
         ●Step2  Figuring solutions out in more complicated cases that require using recursion. This recursive function will continue call it self until it reaches to base case and then starts from the next element and call it self again and again. This whole process ends as long as all the elements of the origin object are executed by the function. One of most important thing is that yo set your base case correctly, otherwise the loop would be infinite.
         ●Step3 I think step 3 is optional. Sometimes we could compact our codes into one line instead of using "if...: .....    else: ....." this kind of form. For instance we could use ternary if to make our codes concise.

  To sum up, the point of writing recursion is that breaking a problem down into small pieces -- base case(case that is simple enough) and more complicated case(general case).

   Thirdly, I want to talk about when to use recursion. I believe recursion is widely used in computer science. We learn a lot about Trees, for instance, binary search, calculating the hight and children of a tree or a subtree and so on. In addition, things like sorting algorithms also need recursion. 
   Basically, when you need the help of loop, however, for loop and while loop cannot solve this complex problem, then recursion is absolutely the best choice. Although I cannot deny that sometimes, compared with recursion, the thinking processes of for and while loop are easier, the codes of recursion are more clearer and more elegant.

   In a word, recursion is a good technique to solve problems, because it makes everything clearer and easier.


______________________________________


Reference:
[1] Data Structure and Algorithms in Python