Sunday, 5 April 2015

Last impressions

My second computer science course is over and I think this semester we  really learned some essential materials. I think this course lays a good foundation of my further learning of other program language because I think the things we learned this year are the basic ideas of programming.

1. Object-oriented programming
     By doing three assignments, I think I have a better comprehension of OOP.
     As I wrote in the slog about OOP,  I thinks the object-oriented programming makes our codes readable and easy to change. We can see the structures clearly.


2. Recursion
Best wishes to every one and good luck on finals!


     From my point of view, recursion is the most important part . it is not only about some codes but about the computer science thinking.

3.Tree, BST, Linkedlist,Queue
    I think these ideas are the same regardless the type of language. 
4. Analyse the algorithm 
   This part is kind of similar with what I am learning in csc165. I think this is trying to make us think about the efficiency when programming. I know in some field like HTT, the quicker your codes are, the more money the company will earn. After learning those basic things about programming, I think we need to pay more attention on the efficiency.

What's more, reading others' slog is also very useful.

http://darkfoxnewslog.blogspot.ca/  I read this blog and I  can see his passion even though he is not in computer science program, which is the same with me.  By learning csc108 and csc148, I fell in love with computer science and I decided to add a computer science major in addition to my math specialist.

http://dottoripy.blogspot.ca/ In this blog I really learned a lot. He also does the weekly summary. By reading his summary, I can learn some points that I overlooked.


http://christiangarciacsc148.blogspot.ca This blog is very informative and those pictures he posted are very interesting and helpful.


Overall, I learned a lot in this course and I also developed my interest in Computer Science. I can't wait to learn more during summer!



 



   

    

Week 11

I revisited what I wrote during this semester and I  agreed with what I wrote and I think writing slogs is very useful.

After the whole semester, I have a deeper thought of OOP.  There are some more advantages that I didn't write.

1. By using OOP, programmer can protect some codes from changing by clients. It makes the whole program more stable.

2. I thought in week 3 that an Object Oriented Program is easier to be read. Now I want to add that it also helps the programmers to develop the ideas of designing a program. We need to divide a whole program into "Class". This process helps us to have a clear idea.

3. An Object Oriented Program is much easier to modify and maintain than a non-Object Oriented Program. So less work is needed to maintain it .

But OOP also has disadvantages.For example, an Object Oriented Program usually has a larger size than others and need more efforts. In this case, an Object Oriented Program usually has a lower speed.

Nothing is perfect. Although OOP has some disadvantages, It is still a big development in the history of Computer Science and it is helpful. 





Wednesday, 1 April 2015

Week #10

During week #9, we learned some different materials between that learned before. Those are more about efficiency of codes.I read a blog of one of a student. I found it explains these materials clearly.(http://darkfoxnewslog.blogspot.ca)

We learned how to count the steps about different sorting methods and also learned a new method called quick sort which applied recursion and is more efficiency than those sorting methods we learned before, since those are in O(n^2) but the quick sort is in O(n).

There is a part that I am not that clear is the lg(n).
My confusion point is that the the  meaning of "double 1 before reaching n" .

And I also want to write a summary of sort methods
Bubble sort: Taking the first value, we compare it with the following and swap if they are in the wrong order. Worst case: O(n^2).
Selection sort: Find the suitable value for each position. Worst case: O(n^2).
Insertion sort: For each value, find the right position.  Worst case: O(n^2).
Quick sort: Let the first value to be a benchmark and divide the list into to part. Implement the quick sort to the each part with recursion. Worst case: O(nlg(n)).

I am not good at counting the running time of a specific code. I think this really requires patience.  There are some common tips:

1. Don't forget to check whether we need to at one at the end of the loop or not.
2. Tracking the n with writing every steps down really helps.

Sunday, 22 March 2015

Week #9

Summary of LinkedList
In the week 8, I learned the LinkedList and I have some tips that I want to write down.
1. Always consider at least 3 cases
       1. Empty LinkedList
       2. front = back i.e. only one node
       3. More than one node (general case)
2. Graphs help
       1. Draw the graph in three cases
       2. Go through node by node.
       3. When modifying the LinkedList, draw the graph may help to figure out how to insert or delete.
3. Use while loop to go though every node
       1. Since the LinkedList doesn't have the index to track the nodes so while loop with some conditions may help
       2. When assigning the current_node to the node.nxt, keep in mind that we need to check whether there is a node.nxt (check None case)
       3. Sometime we use both current_node and pre_node
4. A small tricky thing that may be overlooked: Do not forget change the size when we insert or delete.

Sunday, 8 March 2015

Week #8

During week 7, I learned Binary Tree and more about recursion.
I want to write a summary of what I think important to write down.
One of a trick questions is the longest_path function in lab#6.
The solution is :

1. This question use left.path and right.path to go through the tree separately.
2. The last part is easy to be overlooked that we need to add the [node.data] to the longest path. It is commonly used that when going to n.left and n.right we need to check the n.data at the last step.
3. The base case is also very important that the None type should always be the first case to think about.
Similarly, there is another example that emphasized those tricks.


This question also use the left path and right path method and also use the n.value to link with left path nd right path which is basically the same idea with checking the n.value after going through the left path and right path.




To conclude:
1. think about the base case(None maybe leaf)
2.sometime go to left and right separately
3.Don't forget to go back to n.value.



Sunday, 15 February 2015

Object-Oriented Programming (The second slog to be graded)

    I was confused when I saw the name of "object-oriented programming". After searching this on-line, I felt like this was about the Class and Subclass stuff.
    Then I searched more concepts that I didn't understand well. The first confusing concept is “object”. When doing the A1, I was confused with a problem that if a method of the super class was overridden in two sub-classes and the different overridden methods returned different results which belong to different classes, how we should write the contract of the super-class method. I asked professor and got the answer that I could just write it as “object”! Then I know that an int, a list, or a string are all objects.
    After understanding the concept of object, I found a more precise explanation of the object-oriented programming. It focuses on the following items.

Encapsulation
       • Dividing the code into a public interface, and a private implementation of that interface
Polymorphism
       • The ability to overload standard operators so that they have appropriate behavior based on their context
Inheritance
       • The ability to create sub-classes that contain specializations of their parents


    I found these concepts on-line and I think this is a good tutorial source. http://www.cs.colorado.edu/~kena/classes/5448/f12/presentation-materials/singh.pdf
    Based on the concepts above, I searched those I was not clear about and I also want to write down those covered in lectures.
     Interface: In objected-oriented languages, the term interface is often used to define an abstract type that contains no data or code, but defines behaviors as methods signatures. The example I think is that 'Stack' is an interface with methods like pop () and push ().
    Subclass: We used a lot in the assignment. We have the GameState and Strategy as the super classes and specific game state and strategies as the sub-classes and we can inherit the same properties from the parents and override some methods to implement specific behaviors. This makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones.
     After completing A1 and searching the concepts and reading the blog called “invent with python” (http://inventwithpython.com/blog/2014/12/02/why-is-object-oriented-programming-useful-with-an-role-playing-game-example/). I think I understand that why the “OOP” is useful.
      The object-oriented programming makes our codes readable and easy to change. If we have copy/pasted code in the program, changing it requires making the same change to multiple places in the program. If I miss applying the change to some places, the program will fail and it is hard to find this bug. In addition to this, inheriting the methods defined in the super-class which can also meet the requirements of the Sub-classes really help us to get rid of duplicate code.
    I feel like that using Classes to design program can make the codes more clear and we can easy to understand the structure of the codes, which is very helpful when dealing with a long program.
   



  


Thursday, 5 February 2015

Recursion

    During the forth week, we covered the recursion. Although we have not learned to write some beautiful recursive codes, tracing the recursion was also interesting. It is a very powerful and efficient tool. I have never heard about recursion in computer science before. 
   When I first saw it, the first thing that came to my mind was the mathematical induction. I was thinking that they were using a similar idea, which passing the 'n-1' to the 'n' term. But after tracing the recursion, I feel like they are not the same. Mathematical induction is like a 'linear' process, which use the assumption of a present one to get the next one until getting the final result. While recursion is like a 'peeling' process. It is like opening a gift with many layers of boxes covered. After peeling off these boxes, we will get what we want. Recursion divides a problem into sub-problems, which can be treated in the same way.
     Here is an interesting example which is trying to show how handy the recursion is. 
(http://inventwithpython.com/blog/2011/08/11/recursion-explained-with-the-flood-fill-algorithm-and-zombies-and-cats/). 
     

  And I also found this recursive tree online. I like it! I expect to make one after learning more about recursive codes !