This is going to be my last entry for CSC148 course. I am really surprised that it is already the end of the course. Throughout CSC148 course, I was able to various new concepts such as binary tree and recursion. Learning new information on computer programming was enjoyable and interesting. Moreover, whenever I was able to solve a computer code, I felt really proud and happy that I was able to understand the course material.
One of the most difficult challenges I faced throughout the course might be understanding use of lg(b) with an implication of big-oh. However, since I still have a time to review on the course material, I will do my best to understand all the course materials. Additionally, I found the concept of bringing aid sheet to the exam is really an excellent way for students to review the course materials as they write down the note on the aid sheet. Moreover, I think the concept of writing a SLOG entry every week based on the course material is another great way to review the course materials for the upcoming final exams. Although this course was only 4 months long, I am really grateful to professors and Teaching Assistants who were always willing to contribute their time to answer my questions on computer science and course material with utmost effort. Thank you again.
For the last time, I found other SLOGs which I found really worth reading it. It was my pleasure to see many people working on their SLOG with a careful consideration on the course materials.
Here are the links.
http://csc148wendezhou.blogspot.ca/
http://gamer-born-programmer.blogspot.ca/
http://jessewinterslog.blogspot.ca/
Now I need to study for the final exam. I also hope a good luck to everyone in the course and teaching assistants who are having a final exam this month.
CSC 148H1S: Justin's SLOG
Saturday, April 4, 2015
Saturday, March 28, 2015
Week 11: Big-Oh and Reflection on My Previous SLOG posting
This week, the class revisited the topic about big-Oh to solve the best case for the binary tree. I felt no difficulty over the concept of big-Oh as I have already learnt about them in CSC 165 class. What I felt difficult or rather tough is the fact that I did not get a chance to have a tutorial session for 4 weeks which made me hard to review the course material. Not only that, my professor told the class that there is a chance that course marking scheme can be readjusted which I also think it is inevitable given the circumstances.
Unfortunately, there was no lab session which marks the end of the tutorial. I hope the class can have an extra additional review session before the final exam just to be on the safe side.
Anyway, this week, I also revisited and read my previous SLOG postings. I felt that I agree with my earlier self whether it was about the course material review or how both parties, U of T and CUPE3902 need to find a reasonable contract to each other to minimize the impact it will have on the other courses. Thankfully, both parties managed to end the strike. Thus, I can now get a help from T.A. on things that I did not understand.
Additionally, I think it was interesting for me to see what previous me have thought about the course material. Also whenever me in the previous SLOG post said what was difficult during that week, I felt that it was good idea to reflect on my weakness and improve them using my own time. Sometimes I also outlined the term to remember which I think it is a good practice before the upcoming final exam. Moreover, by reflecting on my previous SLOG entry, I thought it was interesting to see the sample problem which I posted to review that week's materials. Among all the entries, I still find Binary search tree the most challenging just like I stated on my entry.
The easiest thing I found on my previous entries is from week 5 on a simple recursion. Although I found the concept of the recursion very challenging at first, with continuous reviews, I think it was the most easiest yet the most important material which I learnt throughout this course. Even later on, I used a recursion on binary tree and binary search tree to check every possibilities in a tree.
As the end of the course approaches, I was disappointed to see how half of students stopped writing their SLOG post just because T.A won't be marking them since the first grading. I always though writing is an important element for a computer programmer as I already mentioned on my first SLOG entry on why geeks should write. Many of my friends told me they either forgot to do it, or thought that the professor won't be grading their SLOG post because of T.A. strike. Sometimes I find hard to see how students are not doing their works just because professor or T.A won't be marking their homework or assignment. I think that is an unreasonable excuse. Since coming to U of T, I always thought it was student's duty to perform their best on any works given. So I will do my best until my graduation. Now that T.A. strike is over, I hope I can get a help from T.A regarding the course material. I am also glad to hear that U of T and CUPE 3902 have managed to find a solution.
Thankfully, I could still find some earnest people's SLOG posting and could see how much effort they put into each of their post despite of the possibility of having no time. I usually write my post before I sleep which makes me to think back on what I did for the week as well as what kind of impression I had on the previous week.
These are slog which I really recommend for reading. I also commented on these site.
- http://gonicsc148.blogspot.ca/
- http://thediaryofageekykid.blogspot.ca/
- http://timothylock.me/sLOG/CSC148/
Above sites are really detailed and their entry was uploaded almost every week despite of 4 weeks long T.A. Strike.
I just realized next entry will be my final entry for CSC148 SLOG, I hope that there is a chance like this to reflect on myself and course materials in second year too. Thank you for reading!!!
Unfortunately, there was no lab session which marks the end of the tutorial. I hope the class can have an extra additional review session before the final exam just to be on the safe side.
Anyway, this week, I also revisited and read my previous SLOG postings. I felt that I agree with my earlier self whether it was about the course material review or how both parties, U of T and CUPE3902 need to find a reasonable contract to each other to minimize the impact it will have on the other courses. Thankfully, both parties managed to end the strike. Thus, I can now get a help from T.A. on things that I did not understand.
Additionally, I think it was interesting for me to see what previous me have thought about the course material. Also whenever me in the previous SLOG post said what was difficult during that week, I felt that it was good idea to reflect on my weakness and improve them using my own time. Sometimes I also outlined the term to remember which I think it is a good practice before the upcoming final exam. Moreover, by reflecting on my previous SLOG entry, I thought it was interesting to see the sample problem which I posted to review that week's materials. Among all the entries, I still find Binary search tree the most challenging just like I stated on my entry.
The easiest thing I found on my previous entries is from week 5 on a simple recursion. Although I found the concept of the recursion very challenging at first, with continuous reviews, I think it was the most easiest yet the most important material which I learnt throughout this course. Even later on, I used a recursion on binary tree and binary search tree to check every possibilities in a tree.
As the end of the course approaches, I was disappointed to see how half of students stopped writing their SLOG post just because T.A won't be marking them since the first grading. I always though writing is an important element for a computer programmer as I already mentioned on my first SLOG entry on why geeks should write. Many of my friends told me they either forgot to do it, or thought that the professor won't be grading their SLOG post because of T.A. strike. Sometimes I find hard to see how students are not doing their works just because professor or T.A won't be marking their homework or assignment. I think that is an unreasonable excuse. Since coming to U of T, I always thought it was student's duty to perform their best on any works given. So I will do my best until my graduation. Now that T.A. strike is over, I hope I can get a help from T.A regarding the course material. I am also glad to hear that U of T and CUPE 3902 have managed to find a solution.
Thankfully, I could still find some earnest people's SLOG posting and could see how much effort they put into each of their post despite of the possibility of having no time. I usually write my post before I sleep which makes me to think back on what I did for the week as well as what kind of impression I had on the previous week.
These are slog which I really recommend for reading. I also commented on these site.
- http://gonicsc148.blogspot.ca/
- http://thediaryofageekykid.blogspot.ca/
- http://timothylock.me/sLOG/CSC148/
Above sites are really detailed and their entry was uploaded almost every week despite of 4 weeks long T.A. Strike.
I just realized next entry will be my final entry for CSC148 SLOG, I hope that there is a chance like this to reflect on myself and course materials in second year too. Thank you for reading!!!
Friday, March 20, 2015
Week 10: Binary Search Tree Mutation
During week 9, I learnt more about binary search tree, mainly about its mutation. One thing that I had to take into account before going to the class BSTNode is that all data in root.left is less than root.data and all data in root.right is more than root.data. At first, binary search tree sounds really difficult for me, but soon, I realized that the concept of BST is really similar to BTNode that I went over the past two weeks.
Now, I am really good at implementing a BST mutation code such as insert and delete which the professor went over for the class because of continuous practices. Not only that, the term test 2 also covered up to BST mutation, thus I was required to learn the materials.
The below example is a basic BST mutation code that the class visited which is "insert".
Now, I am really good at implementing a BST mutation code such as insert and delete which the professor went over for the class because of continuous practices. Not only that, the term test 2 also covered up to BST mutation, thus I was required to learn the materials.
The below example is a basic BST mutation code that the class visited which is "insert".
def insert(node, data):
''' (BTNode, object) -> BTNode
Insert data in BST rooted at node if necessary, and return new root.
>>> b = BTNode(8)
>>> b = insert(b, 4)
>>> b = insert(b, 2)
>>> b = insert(b, 6)
>>> b = insert(b, 12)
>>> b = insert(b, 14)
>>> b = insert(b, 10)
>>> print(b)
14
12
10
8
6
4
2
<BLANKLINE>
'''
return_node = node #need one instance variable
if not node: #case when node is None
return_node = BTNode(data)
elif data < node.data: # case when data in parameter is smaller than BSTNode's data.
node.left = insert(node.left, data)
elif data > node.data: # case when data in parameter is bigger than BSTNode's data.
node.right = insert(node.right, data)
else: # nothing to do
pass
return return_node
(Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Diane/w9/bst_mutations.py)
Please see the comments which I have added for a brief instruction on insert(node, data). I actually found this exercise really helpful, as I can see how recursive code can be used differently. However, I am starting to be curious that instead of BTNode, if I had to use a Tree with three branches rooted at data, how would I approach to a new method of mutation insert? This was a question which I wanted to ask to T.A., but sadly, with strike ongoing, I was not able to ask about this question.
Lab 8 was a similar exercise to BST insert and delete code, so it was easy for me to complete it in few hours.
Because of the term test 2, I only had one class during week 9. Thus, there was not actually many things that I learnt besides BST mutation.
What I found difficult during week 9 is how for BST mutation, one needs to be able to identify every cases that can happen given the docstring and parameters.
Just as a side note, I hope everyone can resolve their problem well whether it is a strike, or exam. With so many things going on recently at the University, I just hope there is a solution which makes everyone happy. Thank you for reading!!!
Saturday, March 14, 2015
Week 9: Linked List
During a week 8 I learnt about a Linked list. Professor told the class that a linked list can be seen as a value and a sub-list. Before going into a further details about a linked list. There were some terms I had to be familiar of. These terms were front and back. The definition of front and back in a linked list is simple, it simply indicates the sequences' front or back.
Furthermore, I learnt about implying mutation on a linked structure. At first, I was having a difficulty over how to ensure that the recursive code works correctly so that my linked list code implementation works in any cases under the assumption that the parameter follows the example of class LinkedListNode. (please note that professors called this class 'LLNode'.)
As a tip to learn a linked list easily, Danny told the class to draw a picture in which how the sequence will be affected if one make a change in a linked list. The most challenging implementation for me was "insert_before" which was from lab 7.
Furthermore, I learnt about implying mutation on a linked structure. At first, I was having a difficulty over how to ensure that the recursive code works correctly so that my linked list code implementation works in any cases under the assumption that the parameter follows the example of class LinkedListNode. (please note that professors called this class 'LLNode'.)
As a tip to learn a linked list easily, Danny told the class to draw a picture in which how the sequence will be affected if one make a change in a linked list. The most challenging implementation for me was "insert_before" which was from lab 7.
def insert_before(lnk, v1, v2):
''' (LinkedList, object) -> NoneType
Insert a new node with value v1 before the first occurrence
of a node with value v2. Do nothing if no node has value
v2.
>>> lnk = LinkedList()
>>> lnk.prepend(5)
>>> insert_before(lnk, 4, 5)
>>> print(lnk.front)
4 -> 5 ->|
>>> insert_before(lnk, 3, 5)
>>> print(lnk.front)
4 -> 3 -> 5 ->|
>>> insert_before(lnk, 3, 7)
>>> print(lnk)
4 -> 3 -> 5 ->|
'''
if lnk.size > 0:
prev_node = None
cur_node = lnk.front
while cur_node and not cur_node.value == v2:
prev_node = cur_node
cur_node = cur_node.nxt
if cur_node:
cur_node = LLNode(v1, cur_node)
if prev_node is None:
lnk.front = cur_node
else:
prev_node.nxt = cur_node
lnk.size += 1
(Source: http://www.cdf.utoronto.ca/~csc148h/winter/Labs/lab07/node_sol.py)
Please see class LLNode and BTNode from lab 7 to understand how ".nxt", ".front", "lnk.size" work.
In this insert_before code, I had to make sure that there exists two variables which will constantly change as the code goes through while loop. Not to mention, it is also significant to realize that lnk.size, which indicates the sequence's index, should be increased by one to check every elements (if necessary, however in this case, once a function finds the first occurrence of a node with value v2, the function does not need to check the remaining elements in a sequence).
Things that I found easy during week 8 was the basic concept of a linked list such as implementing a function such as append and prepend which is a lot similar to stack and queue exercises I did during week 4. Nevertheless, it was still difficult for me to recognize the previous node and current node to be able to "walk two references along a list"
(Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Diane/w8/Linked-Lists.key.pdf).
(Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Diane/w8/Linked-Lists.key.pdf).
I also read required reading on a linked list in week 8 which was a good prep for me to understand about how to implement a recursion in a list. I also learnt about the fundamental ambiguity theorem which describes the ambiguity that is inherent in a reference to a node
(Source: http://openbook project.net/thinkcs/python/english3e/linked_lists.html).
(Source: http://openbook project.net/thinkcs/python/english3e/linked_lists.html).
Now I want to talk about things which happened this week. With strike ongoing, there was no lab this week as well. However, I managed to finish the lab 8 by myself since compare to previous labs, the amount of work given was relatively small.
Another thing I want to mention is about term test 2. Thanks to studying hard for the exam, I think I did pretty well on the term test. Although I am not sure when I will get it back, one thing is certain that this term test 2 was another great opportunity for me to review course materials before the final exam which will take a place in April.
Finally, I wrote some comments on other student's SLOG which I though it was really interesting and worth reading it. It was difficult for me to find many good SLOG website as not many students were willing to write their SLOG entry every week. Here are some slogs' links which were worth reading for me.
- https://nanalelfecsc148slog.wordpress.com/
- http://dominicli.blogspot.ca/2015/03/slog-7-midterm-2-and-bst-mutation.html?
- http://2015-csc148.blogspot.ca/2015/03/impression-of-week-7.html?
Finally, I wrote some comments on other student's SLOG which I though it was really interesting and worth reading it. It was difficult for me to find many good SLOG website as not many students were willing to write their SLOG entry every week. Here are some slogs' links which were worth reading for me.
- https://nanalelfecsc148slog.wordpress.com/
- http://dominicli.blogspot.ca/2015/03/slog-7-midterm-2-and-bst-mutation.html?
- http://2015-csc148.blogspot.ca/2015/03/impression-of-week-7.html?
Saturday, March 7, 2015
Week 8: Binary Tree
During week 7, I was learning about the binary tree. Throughout labs and many exercises I did, I was able to understand how I can be able to do parenthesizing of the tree as well as how to do binary search trees. Thanks to TA's assistance during the tutorial, I was able to get a sense of how different types of tree can be implemented in many different ways to find out the specific points which the user is trying to figure out. One of the most challenging problem I had during lab06 was the very first problem of implementing parenthesizing. However, when I started to think of the implementing this function by parts, I was able to easily figure out the trick to do so.
Moreover, during the lecture, with Danny, I worked on how to evaluate an arithmetic expression that is represented as a binary tree which was interesting for me to look at. After working with several problems involving binary tree, I realized that binary tree is slightly modified version of tree. One thing that caught my attention during the lecture was use of __str__ and __repr__ methods for a binary tree.
Moreover, during the lecture, with Danny, I worked on how to evaluate an arithmetic expression that is represented as a binary tree which was interesting for me to look at. After working with several problems involving binary tree, I realized that binary tree is slightly modified version of tree. One thing that caught my attention during the lecture was use of __str__ and __repr__ methods for a binary tree.
def __str__(self, indent=''): ''' (BTNode) -> str Return a user-friendly string representing BTNode (self) inorder. Indent by indent. >>> b = BTNode(1, BTNode(2, BTNode(3)), BTNode(4)) >>> print(b) 4 1 2 3 <BLANKLINE> ''' right_tree = self.right.__str__(indent + ' ') if self.right else '' left_tree = self.left.__str__(indent + ' ') if self.left else '' return right_tree + '{}{}\n'.format(indent, str(self.data)) + left_tree
(Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Diane/w7/btnode.py)
The above example is str method that was used by the professor to explain how we can represent a binary tree when knowing self.right and self.left. It was actually my first time seeing the use of __str__ method to show a string representation of a binary tree. From the previous CSC108 class, I already knew what was a binary tree, however, it was still interesting for me to see how use of a binary tree can be represented with some modification to __str__ method of class. Thus, this function can let the user to identify the depth of a binary tree clearly.
During week 8, I learnt about the linked list which is a linear sequence of nodes. Some term I had to familiar of with linked list is the concept of tail and head, front and back which are just explanations of how and what linked list is. However, I will go over more about linked list in detail with an example on the next SLOG entry.
Also I was busy doing my assignment 2 with my partner this week. The most challenging part in this assignment 2 was to implement minimax function (in our assignment the name of minimax function was suggest_move) in game strategy which allow the computer to pick the best move out of available moves considering all the possibilities. My partner and I knew that there has to be some recursion involved which let the minimax function to check all the possibilities of the game. Later on, I also figured out that minimax was actually the beginning of the artificial intelligence. Throughout assignment 2, it made me realize that there is no easy way when you implement the code like minimax where we have to consider all the possible outcomes and ways to find the best move. I better start studying for upcoming term test 2!
Another thing I want to comment is about TA strike. This week, all students did not get to have a tutorial on lab07. I hope T.A. strike ends soon with both parties, TA union and UofT to reach a reasonable contract.
Friday, February 27, 2015
Week 7: Summary of Recursion
Before going to what I did this week, I want to go over the details on the recursion which I will be talking about. In my opinion, recursion is a brilliant way for one to be able to call the function inside the function to perform and apply the function to nested lists and its elements. Judging from what I had learnt so far, there are two types of recursion. One is a recursion involving list or non-list. I will use the example from my week 5 SLOG entry to talk about this.
def length(L):
""" (list or non-list) -> int
Return the max length of the list (possibly nested list) in L.
Pre-condition: L should be Python object either list or non-list.
>>> length([1,2,3])
3
>>> length([1,[2,3,4]])
3
>>> length(12)
0
"""
if isinstance(L, list):
return max([len(L)] + [length(x) for x in L])
else: # if L is not a list.
return 0
Trace length([1,2,3,4])
--> max([len([1,2,3,4])] + [length(x) for x in [1,2,3,4]]) # since L is a list.
--> max([4] + [0, 0, 0, 0])
--> 4
Trace length([1,[2,3,4]]) # nested list recursion tracing example
--> max([len([1,[2,3,4]])] + [length(x) for x in [1,[2,3,4]]]) # since L is a list.
--> max([2] + [3])
--> 3
For this type of recursion, programmer has to consider the situation when L is non-list, thus how it will answer the function. The above, example, function length returns the max length of the list, usually, I have used both max, min and sum methods to create a recursive code. Of course, I also should not forget the case when L ,which is our parameter for function length, is a list. By implementing isinstance(L, list), computer immediately check if L is list type Python object. This method "isinstance( )" was one of methods which I have never encountered before, so it was really interesting for me to see how easily I can check whether something is list, int, float, or str.
When one talk about a recursion, you should not forget about tracing a recursion. As one of the examples provided, tracing a recursion shows a clear representation of how the recursive code will perform in various situations. Also when one is required to trace a recursion, a programmer needs to think about all the possibilities that might need to be consider. For function length example provided above, I need to consider the following cases:
- When L is non-list such as string, or integer.
- When L is a list but with no nested list
- When L is a list with nested list
- When L is an empty list
- When L is a list with nested list and nested nested list.
Usually, giving multiple tracing examples which have a different conditions enable for people to recreate a recursive code even without a docstring of the function.
Unlike a recursion involving a list or non-list, the second recursion involves the use of tree. For a tree, you can have a several leaves and internal nodes. This is actually what I have learnt during this weekend. I will use one of examples from this week's lab to explain the difference with the first recursion that I talked about. Please revisit lab 06 (Copyright goes to Danny Heap and Diane Horton) just in case how t which is a part of BTNode to understand the definition of t.left (node or leaf located on the left side of the root t) and t.right (node or leaf located on the right side of root t).
After reflecting on what I know and learn about a recursion, I begin to wonder if there is another type of recursion which is totally different from two recursions I talked about above. However, there is one certain thing that a recursion is also one of valuable basic programming lessons one have to take not just because it uses a lot in programming, but it also gives students a new insight on what computers are really capable of.
As for the summary of Object Oriented Programming, there is nothing new I learnt so far, so please refer to week 6 entry to find out what it is about.
I guess I already talked about most of things I have learnt this week. One thing I found easy about this week's lecture is the definition of leaves and internal nodes. Since I already memorized what these terms mean and how they work, it was really easy for me to follow a course materials. Now I will continue on my CSC148 assignment 2 which also involves a recursion.
I also commented on some of SLOGs that I felt it is good. Bottom links are some of SLOGs I had commented:
-http://chrisc148slog.blogspot.ca/2015/02/entry-3-recursion-recursion-recursion.html?showComment=1425095301984#c6525962159396058506
-http://sarcasticgradientdescent.blogspot.ca/
Just as a side note, today I learnt about there is going to be a strike. I hope both parties, UofT and CUPE3902 unions can find a reasonable terms to avoid a long-term strike.
def length(L):
""" (list or non-list) -> int
Return the max length of the list (possibly nested list) in L.
Pre-condition: L should be Python object either list or non-list.
>>> length([1,2,3])
3
>>> length([1,[2,3,4]])
3
>>> length(12)
0
"""
if isinstance(L, list):
return max([len(L)] + [length(x) for x in L])
else: # if L is not a list.
return 0
Trace length([1,2,3,4])
--> max([len([1,2,3,4])] + [length(x) for x in [1,2,3,4]]) # since L is a list.
--> max([4] + [0, 0, 0, 0])
--> 4
Trace length([1,[2,3,4]]) # nested list recursion tracing example
--> max([len([1,[2,3,4]])] + [length(x) for x in [1,[2,3,4]]]) # since L is a list.
--> max([2] + [3])
--> 3
For this type of recursion, programmer has to consider the situation when L is non-list, thus how it will answer the function. The above, example, function length returns the max length of the list, usually, I have used both max, min and sum methods to create a recursive code. Of course, I also should not forget the case when L ,which is our parameter for function length, is a list. By implementing isinstance(L, list), computer immediately check if L is list type Python object. This method "isinstance( )" was one of methods which I have never encountered before, so it was really interesting for me to see how easily I can check whether something is list, int, float, or str.
When one talk about a recursion, you should not forget about tracing a recursion. As one of the examples provided, tracing a recursion shows a clear representation of how the recursive code will perform in various situations. Also when one is required to trace a recursion, a programmer needs to think about all the possibilities that might need to be consider. For function length example provided above, I need to consider the following cases:
- When L is non-list such as string, or integer.
- When L is a list but with no nested list
- When L is a list with nested list
- When L is an empty list
- When L is a list with nested list and nested nested list.
Usually, giving multiple tracing examples which have a different conditions enable for people to recreate a recursive code even without a docstring of the function.
Unlike a recursion involving a list or non-list, the second recursion involves the use of tree. For a tree, you can have a several leaves and internal nodes. This is actually what I have learnt during this weekend. I will use one of examples from this week's lab to explain the difference with the first recursion that I talked about. Please revisit lab 06 (Copyright goes to Danny Heap and Diane Horton) just in case how t which is a part of BTNode to understand the definition of t.left (node or leaf located on the left side of the root t) and t.right (node or leaf located on the right side of root t).
def height(t):
''' (BTNode) -> int
Return the number of nodes in longest path in BTNode t.
>>> tree = BTNode(23) #please refer to lab06 from CSC148 for any information.
>>> height(BTNode)
1
>>> b = BTNode(8)
>>> b = insert(b, 4)
>>> b = insert(b, 2)
>>> b = insert(b, 6)
>>> b = insert(b, 12)
>>> b = insert(b, 14)
>>> b = insert(b, 10)
>>> height(b)
3
'''
if t is None: # this means if there is no root, internal node and leaves.
return 0
else:
return 1 + max(height(t.left), height(t.right))
(Source: http://www.cdf.toronto.edu/~csc148h/winter/Labs/lab06/additional.py)
Unlike a recursion involving a list, when involving tree, you have just have to call the function without having to use "function(x) for x in L". At first, since I was only familiar with a recursion involving list or non-list, it was a little bit difficult for me to understand. However, with enough practices and help of T.A., I was able to get my code to work properly.After reflecting on what I know and learn about a recursion, I begin to wonder if there is another type of recursion which is totally different from two recursions I talked about above. However, there is one certain thing that a recursion is also one of valuable basic programming lessons one have to take not just because it uses a lot in programming, but it also gives students a new insight on what computers are really capable of.
As for the summary of Object Oriented Programming, there is nothing new I learnt so far, so please refer to week 6 entry to find out what it is about.
I guess I already talked about most of things I have learnt this week. One thing I found easy about this week's lecture is the definition of leaves and internal nodes. Since I already memorized what these terms mean and how they work, it was really easy for me to follow a course materials. Now I will continue on my CSC148 assignment 2 which also involves a recursion.
I also commented on some of SLOGs that I felt it is good. Bottom links are some of SLOGs I had commented:
-http://chrisc148slog.blogspot.ca/2015/02/entry-3-recursion-recursion-recursion.html?showComment=1425095301984#c6525962159396058506
-http://sarcasticgradientdescent.blogspot.ca/
Just as a side note, today I learnt about there is going to be a strike. I hope both parties, UofT and CUPE3902 unions can find a reasonable terms to avoid a long-term strike.
Thursday, February 12, 2015
Week 6: Object-Oriented Programming and Peek at Tree
This week, I learnt about Tree and recursion. Before going over what I did this week, I want to go over few things about object oriented programming.
So what is object oriented programming? Well, based on my knowledge object oriented programming also known as OOP is a code style in which takes a consideration of class, object, inheritance, and many more. This type of programming mainly focuses on object type which act as a data structure. For class, there are two classes which are parent and child. child usually takes what their parent code originally has and modify it. On my week 4 entry, I listed some example of class inheritance as well as how one can be able to use and implement the code of the parent code into child such as using name_parent.__init__(self, example1, example2). Very often object oriented programming also suggests what kind of function you can use on object type defined by the original creator.
My summary on object-oriented programming is that it may look difficult at a first glance, nevertheless, if you keep practice your code implementing both class and inheritance, you may be able to construct a code in which you do not need to type it over again, since the parent class code has the data that is required for the child class code. Since it is my second time learning object-oriented programming, I found very useful how I can just recall what was used from the parent class code and use it on other class.
One more thing I want to talk about is the use of the default in class inheritance. For instance, let's use an example below which is a typical example of class inheritance which I wrote out.
class ParentClass:
""" Information omitted
"""
def __init__(self, example1, example2):
""" Type Contract omitted, please refer to the week 3 and 4 entry for writing a
doc-string for init method.
"""
self.example1 = example1
self.example2 = example2
def add_it(t):
""" Type Contract omitted, please refer to the week 3 and 4 entry for writing a
doc-string for this function method.
"""
raise NotImplementedError('Subclass needed')
class ChildClass(ParentClass): #here, we can see that there is a subclass being used.
""" Information omitted
"""
def __init__(self, example1, example2, score=0):
""" Type Contract omitted, please refer to the week 3 and 4 entry for writing a
doc-string for init method.
"""
ParentClass.__init__(self, example1, example2)
def add_it(t):
""" Type Contract omitted, please refer to the week 3 and 4 entry for writing a
doc-string for this function method.
"""
self.example1.append(t) #assume that self.example1 is a list.
Here, judging from the above example, in ChildClass' __init__ method, there is score which says equal to 0. The use of '=' without using space indicate the use of default value. if the user does not type anything, then self.score automatically is assigned to a value 0. Although I learnt about this in CSC108, I often forget to implement the default method when needed, so just to remind myself again, I put it on this entry.
Now onto this week's materials. This week, I learnt about tree and recursion using tree. What is tree then? The best example of tree coding is Fibonacci tree branches example which helped me how tree actually works in Python programming. Before going into tree coding, there were some terminologies that I had to be familiar of in order to understand this week's lab. Terminologies are as follows:
Terms to remember
Root: Beginning of the tree
Internal node: node with 1 or more leaves
Leaves: node with no child
Arity: maximum branching factor of tree
Height: maximum depth of tree
Some terminologies were interesting such as leaves which has no child. At first, I had difficulty of learning these, but thanks to going over some problem during a lab, I was able to understand it completely without a problem. I will give some example using tree recursion on my next entry, so please get ready for it!
Just as a side note, I got my term test 1 and I did fairly well. So I am really happy right now. Starting next week, during a reading week, I am thinking of doing my upcoming assignment 2 for CSC148 class. Of course, I am also going to read as well, since it is a reading week.
So what is object oriented programming? Well, based on my knowledge object oriented programming also known as OOP is a code style in which takes a consideration of class, object, inheritance, and many more. This type of programming mainly focuses on object type which act as a data structure. For class, there are two classes which are parent and child. child usually takes what their parent code originally has and modify it. On my week 4 entry, I listed some example of class inheritance as well as how one can be able to use and implement the code of the parent code into child such as using name_parent.__init__(self, example1, example2). Very often object oriented programming also suggests what kind of function you can use on object type defined by the original creator.
My summary on object-oriented programming is that it may look difficult at a first glance, nevertheless, if you keep practice your code implementing both class and inheritance, you may be able to construct a code in which you do not need to type it over again, since the parent class code has the data that is required for the child class code. Since it is my second time learning object-oriented programming, I found very useful how I can just recall what was used from the parent class code and use it on other class.
One more thing I want to talk about is the use of the default in class inheritance. For instance, let's use an example below which is a typical example of class inheritance which I wrote out.
class ParentClass:
""" Information omitted
"""
def __init__(self, example1, example2):
""" Type Contract omitted, please refer to the week 3 and 4 entry for writing a
doc-string for init method.
"""
self.example1 = example1
self.example2 = example2
def add_it(t):
""" Type Contract omitted, please refer to the week 3 and 4 entry for writing a
doc-string for this function method.
"""
raise NotImplementedError('Subclass needed')
class ChildClass(ParentClass): #here, we can see that there is a subclass being used.
""" Information omitted
"""
def __init__(self, example1, example2, score=0):
""" Type Contract omitted, please refer to the week 3 and 4 entry for writing a
doc-string for init method.
"""
ParentClass.__init__(self, example1, example2)
def add_it(t):
""" Type Contract omitted, please refer to the week 3 and 4 entry for writing a
doc-string for this function method.
"""
self.example1.append(t) #assume that self.example1 is a list.
Here, judging from the above example, in ChildClass' __init__ method, there is score which says equal to 0. The use of '=' without using space indicate the use of default value. if the user does not type anything, then self.score automatically is assigned to a value 0. Although I learnt about this in CSC108, I often forget to implement the default method when needed, so just to remind myself again, I put it on this entry.
Now onto this week's materials. This week, I learnt about tree and recursion using tree. What is tree then? The best example of tree coding is Fibonacci tree branches example which helped me how tree actually works in Python programming. Before going into tree coding, there were some terminologies that I had to be familiar of in order to understand this week's lab. Terminologies are as follows:
Terms to remember
Root: Beginning of the tree
Internal node: node with 1 or more leaves
Leaves: node with no child
Arity: maximum branching factor of tree
Height: maximum depth of tree
Some terminologies were interesting such as leaves which has no child. At first, I had difficulty of learning these, but thanks to going over some problem during a lab, I was able to understand it completely without a problem. I will give some example using tree recursion on my next entry, so please get ready for it!
Just as a side note, I got my term test 1 and I did fairly well. So I am really happy right now. Starting next week, during a reading week, I am thinking of doing my upcoming assignment 2 for CSC148 class. Of course, I am also going to read as well, since it is a reading week.
Subscribe to:
Posts (Atom)