Saturday, 9 April 2016

Week 12

This was the last week of classes. I am so happy I survived this semester. This week in lecture we learned about the efficiency of recursive algorithms. We did a few examples in class which included search algorithms as well. We also learned about Big-O of recurrence relations and their time complexity. Then we compared a few function to check which was the better one. We also talked a bit about the final exam and how to study for it in order to get a good grade. This week we did the week 9 lab as we didn't have a lab that week because of the good Friday holiday and the week after we had our assignment 2 demo. The lab was quite easy, we had to record the time each search algorithm took with a different n and then make a chart of the data. Overall, for me, this course went really well. I am excited to study other CS courses in the future.  

Thursday, 31 March 2016

Week 11

I feel recursion is one of most important topics in computer science. Week 6 we learned recursion, I also talked about it in my SLOG for that week. At that time, to me it seemed that writing recursive code was comparatively easier than tracing it. Although both of these jobs were hard for me. For test 2 when we were going to be tested for it I had to solve a lot of example problems to completely understand the topic. My main focus was recursion as I knew the rest of the topics well. After doing a number of problems and going to office hours of my professor, I finally learnt how to write and trace recursive code properly. I think office hours are an extremely advantageous thing and every student should make use of it. A few days ago when I was going through some of the SLOGs of other students, I realized that there were only a few who felt the same as I did about recursion. The labs on tree and binary tree were a great deal of help in my process of understanding recursion as they tested this concept very well. Now I can confidently say:




The rest of the topics in the course are not very complicated, one can understand them with little effort. Recursion is the only topic I felt was tricky and it was very easy to get confusing when writing recursive code especially when the base case is not straight forward. I am glad that I have finally aced the topic. Now that we have started learning about Big O, I am anticipating it to be the next difficult topic in line for me. It seems quite complicated so I hope I am able to understand it the same way as I understand recursion.

Saturday, 26 March 2016

Week 10

Assignment 2 was due this week, I think my partner and I did a good job. All our methods and search algorithms were working. The program was also not taking a lot of time to run. Last week we wrote a method to delete a node from the tree, but that was an iterative approach. This week we learned how to write the same method recursively. Again, we discussed several cases and possibilities. The solution for the recursive one had way less lines of code than the iterative solution. We also started talking about the efficiency of algorithms, it seemed to be difficult but I will only be sure once we learn more about it. Since my lab is on Friday, this week the university is closed for Good Friday so I don't have my lab. Next week we are supposed to give a demo for our assignment, we have to explain our understanding of the code. I hope it goes well.

Saturday, 19 March 2016

Week 9

The week we had our term test 2, I found it to be fair. Some of my class mates were saying that it was harder than the morning sections. Next week assignment 2 is due, my partner and I have been working on it since it has been posted. This assignment is harder than the previous one. We have to write functions to get the possible moves that reach to the solution for four different games. We got 95% on the previous assignment so we are hoping to do well on this one too. This weeks lecture was based on binary search trees as well, we wrote methods to insert nodes and delete from the tree. For delete, we discussed different cases and examples the we implemented the actual method. The professor explained it very well so it wasn't too hard to understand. The insert function was quite easier than delete. This weeks lab was based on also based on binary search trees. We had to implement three different functions, they were also recursive like the ones we did for our previous lab. We had to implement a method to get the values from the longest path in the tree and a method to get the values between a certain range. If one understands the structure of tree and binary search tree properly then implementation of any method is not too hard. 

Saturday, 12 March 2016

Week 8

This week we learned about trees and binary trees. A binary tree is a tree which branching factor 2. Branching factor is the maximum number of children a node can have. The children of the tree are called the left and right child. The values in the left subtree are smaller than the node and the values in the right subtree are larger than the value of the node. We talked about tree traversal in lecture this week, there are three standard orders for traversal; in-order traversal, pre-order traversal and post-order traversal. This is an examples of a binary search tree.


In lecture we implemented the special methods. We also implemented two other methods one was contains which checks if the specified value exists in the tree. The other was evaluate, which evaluates the values of the tree based on the operator which is the node. We discussed the height of the tree, as the number of nodes of the tree increase the height of the tree becomes the logarithm of the number of nodes. This weeks lab was based on trees as well, we had to implement three different methods. I did all of them recursively so I didn't find them very hard to do. Next week we have our term test 2, I am kind of nervous for it. Last time I did not write the test because of the fire alarm. I hope I do well on this test.

Thursday, 3 March 2016

Week 7

Recursion

Recursion is one of the main ideas of Computer Science. A common thing done when writing code is to divide the problem into smaller problems and then combine the results. It is mostly used when the problem can not be solved by a for or while loop for example, checking elements in an arbitrarily nested list. One of the exercises we did in lecture was tracing this code:

def sum_list(L):
    """ (arbitrarily nested list of int or int) -> int 

    Return the sum of all ints in L. 

    >>> sum_list([1, [2, 3], [4, 5, [6, 7], 8]]) 
    36 
    """ 

    if isinstance(L, list): 
        return sum([sum_list(x) for x in L]) 
    else: 
        return L  

In the code above, the function sum_list is calling itself inside its own definition. It keeps on looking inside the nested lists until there are no lists left and returns the sum in the end. There are three helper functions used in this code, sum, isinstance and sum_list. Our base case is when L is an integer, we do not need recursion for this. So, when the function is called on an integer, it will the integer. For example, sum_list(25), L is not a list, so the if condition is false and it returns L which is 25 in this case. Here, recursion is needed when calling the function on nested lists. For example,

sum_list([4, [1, 3, 5], 9]) -> sum([sum_list(4), sum_list(1, 3, 5), sum_list(9)])
                                      -> sum([4, sum(sum_list(1), sum_list(3), sum_list(5)), 9])
                                      -> sum([4, 9, 9])
                                      -> 22

Recursion is basically a method where the solution of a problem depends on smaller instances of the same problem. Recursion is very useful, big problems can efficiently be solved by dividing the problem into smaller versions and then combine the results to get the solution to the big problem. Recursion actually helps in saving up so many lines of code. Recursion is so far my favourite topic. Although sometimes it does get quite hard to trace the code but it is an extremely useful thing. A code with recursion looks beautiful but it is hard to understand at first.

Friday, 26 February 2016

Week 6

This week's lecture was about recursion is a way of defining a functions in which the function is applied in its own definition. It is one of the main ideas of Computer Science. A common thing done when writing code is to divide the problem into smaller problems and then combine the results. It is mostly used when the problem can not be solved by a for or while loop for example, checking elements in an arbitrarily nested list. One of the exercises we did in lecture was tracing this code:

def sum_list(L):
    """ (arbitrarily nested list of int or int) -> int 

    Return the sum of all ints in L. 

    >>> sum_list([1, [2, 3], [4, 5, [6, 7], 8]]) 
    36 
    """ 

    if isinstance(L, list): 
        return sum([sum_list(x) for x in L]) 
    else: 
        return L  

In the code above, the function sum_list is calling itself inside its own definition. It keeps on looking inside the nested lists until there are no lists left and returns the sum in the end. There are three helper functions used in this code, sum, isinstance and sum_list. Our base case is when L is an integer, we do not need recursion for this. So, when the function is called on an integer, it will the integer. For example, sum_list(25), L is not a list, so the if condition is false and it returns L which is 25 in this case. Here, recursion is needed when calling the function on nested lists. For example,

sum_list([4, [1, 3, 5], 9]) -> sum([sum_list(4), sum_list(1, 3, 5), sum_list(9)])
                                      -> sum([4, sum(sum_list(1), sum_list(3), sum_list(5)), 9])
                                      -> sum([4, 9, 9])
                                      -> 22


The function calls itself on each list. This is how recursion works.

This week's lab was on list comprehension and unittests, we were given code we just had to rewrite it without using list comprehension and also write test cases for each function. It was very easy.


Friday, 12 February 2016

Week 5

We had our first term test this week. Unfortunately, I was one of those who did not give the test due to a fire alarm that rang as soon as the test began. The test was quite easy, I would have easily gotten a good grade. This week we studied about linked lists, which i felt was the most difficult topic that we have done till now. Linked lists are linear sequences of nodes. We defined two classes in lecture; LLNode, to represent a single node and a wrapper class, LinkedList, to represent the list as a whole. We also talked about traversing a linked list and mutating a linked structure. In the LinkedList class we implemented functions to prepend and a contains function. the professor gave very good examples to aid our understanding. He chose a few students and pretended that they were lists linked to each other. So, that was very helpful. This week's lab was also on linked list, we had to write a few methods for them. Linked lists are very confusing, one needs a lot of pictures to understand them. It is very easy to mess up. The quiz was also on this topic, which i did not know how to do. I will have to practice more questions on this topic. I am quite stressed about what Danny and the department will decide about our term test. Assignment 1 is also due after the reading week, I hope my partner and I do well on it. Here is an example of a linked list and the code for the contains function:


 def __contains__(self, value):
        ''' (LinkedList, object) -> bool
    
        Return whether LinkedList (self) contains value.
    
        >>> lnk = LinkedList()
        >>> lnk.prepend(0)
        >>> lnk.prepend(1)
        >>> lnk.prepend(2)
        >>> lnk.__contains__(1)
        True
        >>> lnk.__contains__(3)
        False
        '''
        current_node = self.front
        while current_node:
            if value == current_node.value:
                return True
            current_node = current_node.nxt
        return False    

Friday, 5 February 2016

Week 4

It's the fourth week of classes and it seems like forever. I have so much work to do! So this week we did Stacks and Queues, and started talking a bit about linked lists. Stacks are very easy to understand with real life examples. Some one in the lecture gave an example of a suitcase with clothes, the first piece of cloth to go in is the last to come out and the last to go in is the first to come out. This made me understand stacks very well. I find them very easy to deal with now. We learned about unittests, which i personally find very confusing. Linked list also confuse me at the moment, but we have just been given an introduction so hopefully i'll be able to understand after we talk about it in detail with some examples. This week's lab was based on Stacks and Queues, I found it quite easy. The methods we were supposed to implement were not complicated. Plus, the great thing was that the quiz was also based on Queue, we had to write what the result of the given function was. Next week, we have our first term test and I am not too confident about it. I am extremely nervous, but I hope it goes well!

Tuesday, 26 January 2016

Week 3

We started this course with some review of python. We did some of the basic things like the mutable and immutable data types. We learned that '==' means equality of values in the memory and 'is' means equality of addresses in the memory. We went over some examples in class. Im glad we reviewed the previous basic material as I had forgotten some of it. After the review, we started with the material for this course. We talked about classes and what they represent, the methods and attributes that a class has. We then developed a class called Rectangle. I was having some difficulty with the new format of the type contracts in the beginning as I took CSC108 last year and we used to write type contracts in a different way. I had to go over a few examples several times to get them right. In the second week, we developed 3 classes and learned some key terms of the OO world. The material posted for reading was very helpful, it contains thorough detail on the material. Adjusting to PyCharm was an obstacle for me, I had previously used Wing. Also, I changed my laptop and PyCharm was giving me a hard time as it was not working properly. Labs also started this week, we had our first lab assignment and quiz. I found the lab assignment quite hard as I haven't been in touch with programming since a while. The good thing was that the quiz was extremely easy. I really like my TA as well, she is very friendly and helpful. Overall, I thought the material up till now was challenging. I requires a lot of thinking and logic. But I am sure once I go over the material again I will be able to understand it.