Sunday, April 5, 2015

week 12 : last impressions

This week is the end of my first year in university! I am so excited that I want to write my summary of CSC148 and my impression.



In summary, we learnt:
1.Object-oriented programming which includes "class", "subclass", "inheritance" ,etc...
2. Recursion which is the hardest part of this course.
3. Abstract data base (including tree, binary tree, binary search tree, link node and link list)
4. Programming efficiency (different kind of "sort" and "search:)
5. unittest, assertion

As there is an end of this term, my advice for the future students is that we should attend labs seriously and  keep professor's announcement for assignments in mind and do our best to complete assignments.
For me, assignment 2 is really hard. It took me a whole weekend to construct my program and figure out an algorithm but wasted another whole week to debug!
I have just finished assignment 3. Although it is easier than assignment 2, I misunderstood the requirement as first. On Monday's lecture, Diane posted a announcement as following. (She is so kind! Without the announcement, I would fail )















"Don't flatten the tree" is what surprised me. In fact I flattened the tree!

In a word, just as Diane said, CSC148 is just a start for computer science! It still has a long way to go and I look forward to the future courses.

Sunday, March 29, 2015

week11: Revisit my earlier SLOG and visit my friend's slog

In this week's slog, I will revisit my earlier SLOG and check my earlier ideas.


In my week4's slog, I wrote:"self was very trick for me. But I decided not to understand but to remember it! For every method in a class, remember writting self!!!" However, now I understand that "self" is just the class itself. So when we call method in a class, "self" tells system which class is used.


In week7's slog, I wrote my point of view for benefits of Object-Oriented Programming. Now after finishing my assignment 1&2&3, I get another point. Using class is quite convenient to add something new to your code! In assignment 1, we wrote "subtract_square_state.py" and in assignment 2 we wanted to write another game state called "tippy_game_state.py". By using class we can keep "subtract_square_state" in place and wrote another class inherited from super class "game_state".



(Here is the result in python shell after running "Game_view". By using class we can choose the game which we want and choose strategy.)


In my view, it is efficient if the program is huge.I also find that it is efficient for "debug" because we can choose different games to check our code as we want.

Another point which is worth mentioning about OOP is that I find our code  is much easier to understand by using class.
For example:


In class Queue, it is quite clear that this data type is something like a list and we can add data using method enqueue. Using class is much easier for us to understand the code than just providing a branch of functions.


I also visited my friend's SLOG this week. What is worth mentioning is my partner Celina's slog!




I found something useful in her slog. In week 7, she gave a summary for abstract data types. After giving a summary for each type, she provided a website link such as:
"http://interactivepython.org/runestone/static/pythonds/BasicDS/TheStackAbstractDataType.html"
I visited those website and found it is quite a good summary for abstract data types!

It gives a summary for each data type and give an example for each method!

I have highlighted this website! Thank you Celina~!


Sunday, March 22, 2015

week10 my impression on week 9

In week 9,we took term test 2. In lecture we talked about how to insert and delete elements in a binary search tree.

In test, the hard part for me was a question called "visit in order". In fact I didn't hear about it before the exam and I didn't have a expression about we talked about it in class.

After the exam, I talked about traversal with my friends but they couldn't give me a clear answer too! So I searched it using google and I found the answer.

The tree pictures below represent traversal in-order,pre-order, post-order and level-order quite clearly.

 
 

In week 9, we only had one-hour lecture, and we talked about how to insert and delete elements in a binary search tree.

To be honest, the "delete" method bothered me until now.I didn't get the point about how it works.

The code for "delete" is at the end of the slog.

Firstly,why shall we write "elif not node.right" ? Can we just write "return_node == node"?

Secondly, what dose it mean by "node.data = find_max(node.left).data"?


To solve my problems, I decide to attend next week's office hour.

Sunday, March 15, 2015

week9 :my impressions of week 8( LLnode and LinkedList)

This week we talked about LinkedList and LLnode.

LLnode is just a single node.

A linked list is a linear sequence of nodes. Each node has a value and a child which keeps reference to the next node. It also has a parameter called front and another parameter called back. "Front" refers to the first node of the sequence.But it has a child which refers to the second node. "Back" refers to the last node of the sequence. But its child is a "None".


For me, this week's material is even harder than recursion!
On Monday's lecture, I was really confused by the difference of LLnode and LinkedList. Because both of them have a child and both of them have a value.
I also couldn't tell the difference between some concepts which occur in codes. (For example: "front","next node","current node".)
After class I asked my professor for help. She showed me a picture(as following)








Just as indicated, "Back" is the last node of a sequence and "front" is the first. However, "front" contains a child. So, in fact "front" indicates the whole sequence. But we often use the expression "current_node = front". In this case,
we can use "current_node = current_node.next" to move forward.
By the way the difference between LinkedList and LLnode is that LinkedList is consisted of LLnode.




















Like the code above, we want to get the value of a particular node. So we use expression " current_node = front" to initialize and "current_node = current_node.nxt" to move forward.
INSIGHT: we can't write "current_node.next" because next if a function in python.

Sunday, March 8, 2015

week 8: my impressions of week 7 (btnode)

In week 7, we talked about binary tree and binary search tree.

Binary tree is a tree whose nodes have at most two children.Binary search tree is a binary tree in which the value of left child is less than the value of node and the value of node is less than the value of right child.

Prof Diane drew two pictures which are quite useful for us to understand the concepts in her class and I drew them again using computer and post here.
The left picture represents binary tree and the right represents BST.


 


In lecture we also talked a very important thing which we should keep in mind. That is :"__init__" in class "binary_tree" is different from class "tree".







We set "left==None" as a default. This means if a node don't has a left child then its "left" will still exist and its value will be None.


Although binary tree and binary search tree were not hard to understand, I still met a question in this week's lab!

The head of the question is list_longest_path.










I got confused about how to get a whole path! The only thing came to my mind is that I could write a recursion to create a list holding all nodes. But I didn't know how to get a particular path! Even worse, I didn't finish all the questions in my lab time so I didn't have a chance to ask my TA about it.

Then I posted a question on Pizza! To my surprise, my prof answered it quickly!
According to her ,my should take advantage of some properties of binary tree. That was : "binary trees have only two children." so  we can check them one by one. After some test, I got it.

Here is the solution which is posted on course website for this function.






Sunday, March 1, 2015

week 7 summary of recursion

I want to start this week's SLOG with a gif picture.

  This is my first impression with recursion when we talked about it in week4's lecture ! 
  
  Recursion is a kind of arithmetic which we call itself in its function body. It is the most difficult concept which I have learnt because it's sometimes difficult to trace a recursion, not to mention we write it ourselves.
  
The way I solve this problem and try to understand recursion is practice! After going through all of the lab materials and additional problems, I am much more familiar with recursion.Frankly speaking I go on well with assignment 2!

There are some thing we need to take care when we write a recursion.
1. we need a base case. Without a base case , a recursion function will run forever.
2. for a base case, we need return a value. Only in this case we can call the base case in more complicated situation.
3. the list expression [ fun(x) for x in ] is quite useful in recursion.

However,is there some  patterns for writing recursion?
YES!
I used to follow the following steps.
1.I consider the base case. Regard the object as the simple way and return the expected value.("if expression")
2.Just have a try! Write the "else" expression using the base case! then you have to design a complicated example and trace it. You may fail in the first few times. But I always get it in the end.


Here is a example .










For function sum_list,
1. we consider the base case.(ie. 1) then sum_list(1) = 1
so we write "if expression" as following:






2.we write the "else expression".
First I try like this:






But after tracing a few complicated example, I realize that this obvious wrong because we return a list! so we add "sum"! then we get it!








In summary, after few week's studying, recursion is not that difficult for me and it is a quite efficient way to solve problems of different depth.

Sunday, February 15, 2015

week6: my impression of week5 and week6 My summary of Object-Oriented Programming concepts

In this week's slog, I will talk about my impression on week5 and week6 and give a summary of objective-oriented programming concepts.



Last week we talked about stack and queue and a little more about recursion. Stack and queue are containers of data. We can add elements to the end of the stack and delete the element in the end. On the contrary, we can add elements to the start of the queue and delete the element in the end. It just likes the model of lineup at a coffee shop or vending machine.


Queue and stack can be complicated, such as [1,[2,3],[[4,5,6],7]].
It is easy for us to get lost when we trace it. And the method which we use to deal with queue and stack is recursion.

When it comes to trace recursion. To be honest, I don't like it because it can be complicated. For example, I got lost when I traced the list on last week's lab.
(find the max one of [4 ,5, [6,7,[3,9,0], 6],10]). I asked my TA in help center and I figured out some efficient way to trace: The key thing to trace a recursion is to apply your function step by step. We can't (and not possible) to figure out the final outcome all at once.


This week we talked about Tree. A tree is a container of data with children.
We can put value in a node and edges connect node with nodes.


One of the most important thing which we need to keep in mind is that a tree both has value and many children and children have their own values.


After 6 weeks of studying, we have learned a lot about Object-Oriented Programming. We have learnt how to write a class, how to write a subclass and inherit methods from super class.In this week's slog I want to make a summary of concepts of OOP.

First, some concepts of OOP:

1.objects .it is the basic unit of OOP. Objects can be a function, can be a list of integer.

2.class. Class is a container of methods and data.

3.Subclass. Class can inherit some methods from super class and share some properties.

4.inheritance. subclass can inherit methods from super class.


SO  what is oop?

In my mind, oop is a programming style which focuses on objects and their properties rather than actions. For example, in week three we wrote a class “employee” .Then “employee” was our object then we considered what we need to do with this object in our program. We wanted to record the money which was paid to employees and record the total amount of money which we paid. So we added several methods into the class, such as “record pay”, “total pay”. Then we found that we need more information to complete methods. So we wrote subclasses :“hourly employee”and "weekly employee".  
In a word, oop is programming language model, and we write classes to achieve our goals.

Then, what is the benefits of OOP?

The first thing which comes to my mind is inheritance. As I mentioned above, we wrote subclass and let them inherit methods from super class. It is possible to define lots of subclasses which share some properties of the super class. It is quite efficient.

In a word, OOP is a useful programming method to improve efficiency, and I guess we will continue learning about it through the term.

Sunday, February 8, 2015

week 5: my impressions of tracing recursion from week 4

Week 4 was a really busy week because assignment 1 was due on Thursday.At first, I can't figure out the difference between Game_view and Game_state. After attending Danny's office hour, I got it. Game_state is about the current state of the game, and Game_view is just to start the game.In lecture,we talked about recursion .If we use recursion we can generalize some arithmetic and simplify them.For example, if we want to get the sum of a list of lists without recursion (ie,[1,2,3,[4,5]]) , we should use two "for" loop, and the code could be complicated. If we want to get the sum of a list of lists of lists (ie, [1,[2,[3,4,5]]]), we should write another program using three "for" loop. However using recursion, all these things are the same!In the lab, there is a quite interesting question at the end of the handout, I post the docstring with my own code below which is different from my TA’s answer.




















When it comes to trace a recursion. It is not a very hard problem for me because I learned a bit of recursion in my high school. Prof. Diane represented recursion on the black board carefully and clearly, so I got it.

Saturday, January 31, 2015

week 4 , my impression of first few weeks

In first week and second week,we talked about object-oriented programming. It was not a hard topic for me, because I had just finished CSC108 and we had known what was class, how to write "__init__", "__str__". I got confused with method "__repr__". I didn't know the difference between it and "__str__". But now, after going through assignment one and consulted some materials, I understand "repr" is a method which returns a string that can construct an object with the same value. It represents a string for computer itself rather than people and "__str__" is designed for people.

Also, "self" was very trick for me. But I decided not to understand but to remember it! For every method in a class, remember writting "self"!!!

In third week, we started to talk about inheritance,we wrote subclass and let them inherit methods from super class.


I like the example which we talked in the class so I post here and I should remember how to write a subclass.

















NOTICE that we inherit "__init__" from super class!



And this week, we started to talk about recursion! I heard about it when I was a senior high school student and I will post my impression for recursion next week.

Thursday, January 22, 2015

week3: why geeks should write

In this semester , I will keep posting SLOG for CSC148 every week.

The first topic is : why geeks should write. 

As we use writing skills in our daily life. The first word which comes to my mind is “record”. People write in order to record their ideas, remind themselves what is important.


Secondly , we write something for the purpose of communication. For example, we write down our programs so that others can understand what we want to do. At the same time, we can write programs in order to communicate with computer. If I write “1+1” in python shell, my computer knows I want to do some easy addition.In a word, writing is an essential and important skill in modern society.

Particularly, writing plays an important role in debugging! In fact, I used to form an algorithm in my mind before starting writing a program. Usually this can't run at first. Only when I wrote my code down, I can run debugging program and figure what's wrong with my code!