2015年4月9日星期四

Last Impressions: Look Back Over the Course, Conceptual Hurdles, and Course Events(Week 12)

  I can't believe it was the last week of the whole semester! As we walked into our lecture, we were asked to fill out a survey. Some of the questions are like "Did you enjoy writing slog?" and "Did we benefit in terms of understanding course content by writing the slog?" I want to say, yes! At first, I felt extremely funny that we were asked to write about "why geeks should write?", I even didn't know why! How could I finish this work? However, after weeks, I started to understand why we were supposed to write slog. It gave us a chance to think and organize our knowledge.

  The first things we know from this course were abstract data types and object-oriented programming. And they did sound "abstract" to me. During the days that working on assignment1, my group went through a very difficult time. So did things in lab. I was told that I didn't understand OOP at all..., which hurt me a lot. However, after finishing assignment1 and the third-week(or forth-) lab, I felt things were clearer. Finally, our work got a very high and very surprising mark. Then I started to worry about test 1, because I didn't think I can handle it and I even wanted to give up (mainly because of suffer from doing assignment, haha). However, the result surprised me again.

  Then we started to learn about recursion, which was much more difficult than class and subclass. At first, I thought it was quite easy, because the only thing we need to do is trace recursion, which was easiest part for recursion. That was the first time I felt lab was easy...  Thanks to professor, knowing how to trace recursions made a easy start. After that, labs became quite difficult. And after learning trees, I realized that the purpose of the recursion related exercise was to introduce us to the mechanics of recursive thinking, which help us writing more complicated codes such as codes about trees and so on. it was the the time of learning recursion that I read a lot of contents from some classic books of python.

  After recursion, we started to learn trees. I have to say that there was nothing called "easy" for CSC148. Tree is amazing, which also bring lots of "amazing" difficulties for me. I love the way that trees work, it was brilliant. The one who invented it was extremely intelligent. My favorite tree was BST, it is a good way to collect and filter information. Then we took tests 2. It was a disaster for me, because I forgot to go through Linked List... So I did quite bad because of losing all the marks of the last question. This gave me lesson that I'm supposed to review every day and every week and make sure I understand everything w learnt clearly.

  The last week, we learnt running time analyst that was quite similar with we we learnt in CSC165. It was just like a review session and there was nothing very difficult.

  Overall, I enjoy CSC148 a lot, although I cannot deny it was not easy for me. However, I love challenges and also I love the things I learn from those challenges. I think I'm at the gate of computer SCIENCE now. I'll keep reading, writing, thinking and practicing as I did in this semester.
  I appreciate my professor bringing those amingzing courses to us. I appreciate my TA who was very patient! Thank you for reading my SLOG!
  I love CS!




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

2015年2月25日星期三

Summary of Object-Oriented Programming Concepts(Week 5)

  It's my first time to know object-oriented programming(also known as OOP) concepts. We already have used the knowledge about this while doing assignment 1.

  "In object-oriented programming, computer programs are designed by making them out of objects that interact with one another." said by two computer scientists. In CSC108, most of the time, we were using procedural programming, which mostly focuses on writing functions. However, as these two scientists concluded, OOP mainly concentrate on both data and functions, which means class (including superclass and subclass), inheritance, interface and methods are of vital importance.

  According to the sentence mentioned before, the very first thing we need to know is "object". Obviously, "object" is the key to understand OOP. Object has its won properties and state, just like every object in our daily life. Also, object could expose its behavior through methods.

  Secondly, what is "class". Class is the blue print of a program. It help us organize our thoughts and makes your codes readable for others. It's like building a house, class is the frame. After building the frame, we need to put things in the frame, which are our functions. 

  Thirdly, speaking of class, one of the most important thing is the relationship between superclass and subclass. They are like parents and children respectively. Children could inherit all the characteristics of parents,which is known as inheritance, and of course, develop their own uniqueness. In my opinion, superclass-and-subclass relationship is one of the ways that make interaction between objects possible.

  The last, "interface" and "method". An interface is a contract between a class and the outside world. Objects define their interaction with the outside world through the methods that they expose. We've already learnt four main methods which are the most common form -- "__init__", "__str__", "__repr__" and "__eq__". Each of them has its own unique role. "__init__" is used for initializing, "__str__" is for printing, "__repr__" is for evaluation and "__eq__" is for comparison. All of them make the class more formal about the behavior that it acts.


  There are a lots of things we need to learn about OOP and I believe it's the main target of CSC148. Although it's kind of difficult at first, I still find it interesting and I'm looking forward to learn more about it.