Thursday, 2 April 2015

Week 12



So this is the last Slog and the last week of classes. The strike is finally over, unfortunately, we missed one month of labs. I was enrolled in Diane's class and my learning experience was amazing. The way she taught the course kept my interest intact, I did not lose interest at any point in the course. I hope to be taught by her again. This week we have to submit assignment 3 which I found to be a lot easier than the previous assignments. I was expecting an extremely difficult one considering the difficulty level of the previous two. Thankfully, we had two options to choose from in this assignment. When doing the assignment, I was quite surprised about how easy the assignment is.


We also got our Test 2 back, I was quite disappointed by my mark. In lecture, we learned about the speed of search for different data types and speed of sorting of different sorting algorithms. We talked about Big O, I had already learned this since I had CSC165 last semester. Therefore, I did not find this concept challenging. Overall, I enjoyed this course and also learned a lot, it was quite helpful since we learned about abstract data types, recursion, object oriented programming and many other topics. My learning experience would have been perfect if the strike had not taken place. 

Sunday, 22 March 2015

Week 11



Recursion is an extremely important topic. Week 5 I talked about recursion. At that time, recursion seemed quite hard to me. I found it very difficult to trace recursive code and also writing it was quite hard for me. I hated recursion back then. After assignment 2, when we had to write recursive code, I kind of started to get the hang of it but I still wasn't good at it. I was still finding recursion hard. In test 1, I lost most of my marks in the question where we had to trace recursive code. For test 2, my main focus was to understand recursion completely and be able to write recursive code perfectly. After studying it properly for test 2, I finally understood recursion. Since then, I have started to find it easy. Whenever I am attempting a question now, I always think why I found it so hard because now it seems so easy. I was going through some of the SLOGs, I felt many people found it easy and interesting but there were a few who also found it hard. Overall, majority loved recursion and thought it was quite easy. This week we discussed the strategy 'Minimax' which we had to code for our assignment 2. Minimax is only thing that I hate the most in this course. I feel it is something that I can never code right.


Sunday, 15 March 2015

Week 10

We had our term test 2 on the 11th of March, which is why we only had one lecture this week. I found term test 2 a bit harder than term test 1, but overall it went fine. This week we studied more about binary search tree, we implemented an insert and delete function. For the delete function, we went over the algorithm first in plain English and then translated that to python language. I thought this was a perfect way to do the coding, it made it quite easy. I will definitely follow this technique in the future. This is how we did that:

Algorithm for delete:
     1. If this node is None, return that
     2. If data is less than node.data, delete it from left child and
         return this node
     3. If data is more than node.data, delete it from right child
         and return this node
     4. If node with data has fewer than two children,
         and you know one is None, return the other one
     5. If node with data has two non-None children,
         replace data with that of its largest child in the left subtree,
         and delete that child, and return this node
    return_node = node
    if not node:
        pass
    elif data < node.data:
        node.left = delete(node.left, data)
    elif data > node.data:
        node.right = delete(node.right, data)
    elif not node.left:
        return_node = node.right
    elif not node.right:
        return_node = node.left
    else:
        node.data = _find_max(node.left).data
        node.left = delete(node.left, node.data)
    return return_node

This was extremely helpful. 

Sunday, 8 March 2015

Week 9



Finally we submitted assignment 2 on the 5th of March. Implementing minimax was a tough job. The coming week we also have term test 2. This week we talked about linked lists, which 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 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 as we did for the binary trees. I found the code for the contains function for linked lists much easier than the one for the binary trees. There were fewer lines of code as well. 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    

Since assignment 2 was due, most of our lecture time was used for discussing the assignment, which was pretty useful, and so we didn't cover much material.

Sunday, 1 March 2015

Week 8

The coming week assignment 2 is due, my partner and I have been working on it the whole week. Assignment 2 is quite hard especially minimax. This week we studied about binary trees. A binary tree is a tree with branching factor 2. The children are called the left and right child. We talked about tree traversal, there are three standard orders in which to traverse; in-order traversal, pre-order traversal and post-order traversal. We also talked about binary search trees. This is an example of a BST:



In lecture we wrote some code for binary tree node. We implemented a function which returns whether the binary tree contains the specified value. We wrote two different versions on this function.

def bst_contains_v1(node, v):
    ''' (BTNode, v) -> bool
    
    Return whether the binary tree rooted at node contains v.
    
    Assumption: node is the root of a binary search tree.

    >>> b = BTNode(5, BTNode(3, BTNode(1), BTNode(4)), BTNode(7))
    >>> contains(b, 17)
    False
    >>> contains(b, 5)
    True
    >>> contains(b, 3)
    True
    >>> contains(b, 4)
    True
    '''
    if v == None:
        return False
    elif v == node.data:
        return True
    elif v < node.data:
        return contains(node.left, v)
    else:
        return contains(node.right, v)


I found this version to be easier than the other one.

Sunday, 22 February 2015

Week 7 - RECURSION

RECURSION

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 exercise 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.

                          

Sunday, 15 February 2015

Week 6

This week we got our term tests back, I did not do very well but I am happy that I passed. This week we started a new concept of trees. A tree is a set of nodes with directed edges between some pairs of nodes. The edges connect the parent nodes and the child nodes, each node has exactly one parent. Trees can basically be used to represent hierarchical relationships, for example, inheritance in a program. Another cool thing we learned was ternary if. We can write long if statements in one line now. We wrote some code for the tree, at first I was quite confused but later when I read it thoroughly I kind of understood the concept. We also did a worksheet in class which had different questions about trees. This week's lab was also based on trees, we had to write some methods for it. The quiz in the end was also about the same topic, I feel I understood the concept more after the lab that's why I was able to easily answer the questions on the quiz. Finally, next week is reading week, I will get some time off to relax and take my mind off the hectic schedule. But, I am not going to miss this opportunity to catch on topics that I don't understand very well like stacks and queues. So, I'm going to take 2 or 3 days off and then start studying.

Object Oriented Programming


Object oriented programming (OOP), as the name suggests, programming based on 'objects', these objects are data structures. OOP contains methods such as inheritance. Inheritance is a method used when creating different classes, it is when a class is based on another  class. There are child classes and parent classes, the child class inherits all the methods and functions from the parent class. In CSC108, we did not see this as much but in this course we have only been working with classes and its methods and so I am quite familiar with this method. Inheritance is very useful since it helps in avoiding repetitive code. Classes contain other methods as well, such as __init__ which is used to initialize an object in the class, __eq__ which is used to compare two objects, __str__ for a string representation of the object and __repr__ for a formal representation of the object.


Sunday, 8 February 2015

Week 5

This week we had our first term test on Wednesday, the test wasn't so difficult but unfortunately I had my MAT137 test on the same day so I couldn't prepare for the term test very well. On Monday there was a snow storm which is why I was not able to attend the class and in our Wednesday lecture time slot we had our term test. From what I understood from lecture's codes posted on the course website, the prof talked about test cases in unittest. She had a code according to which they implemented some test cases. Another thing discussed in class was a 'bracket balancer' code, this code returned whether the given line had balanced brackets i.e. same brackets on both ends of the line. This function basically looks like it's written to ensure that none of the brackets in a line or an equation are missed out. This week's lab was about stacks and queues, and for the first time ever since labs started I was able to finish the lab exercises on time. This week's quiz was also based on queues so it wasn't so difficult.

Recursion


Last week we started learning about recursion. I feel one of the main ideas in Computer Science is recursion. 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.


Saturday, 31 January 2015

Week 4

Time goes by very fast, it's already the fourth week of classes. Seems like the semester just started. So, this week we had our first CSC148 assignment due, I did it with a friend of mine, we were partners for this assignment. This assignment was a big jump from the assignments for CSC108, we had a lot of difficulties tackling the assignment. Thankfully we completed it in time. In this assignment we were supposed to write a game named 'Subtract Square'. Basically, in this game a number is given at the beginning, the player and the computer take alternate turns and choose a square number. Each time that number is subtracted, the player to bring the number to zero wins the game. Writing this game was quite a task, not only did we have to write this game but also write generic classes so that later in future assignments we can add more games to those classes. Now, the coming week we also have our first CSC148 midterm. I am quite nervous for it because I feel that I am not properly prepared for it. And I also have my MAT137(Calculus) midterm on the same day so for me the coming days are tough. 

Every week we have two lectures and 1 lab. This week was all about tracing codes. We did a few recursion exercises in lecture and this week's lab was also related to same topic. We also talked about the merge sort algorithm. This week we had easy topics.


Saturday, 24 January 2015

Why geeks should write

Since geeks are always programming and doing other activities related to computers. They are extraordinary in the field but at the same time they should know how to express themselves. Not only express themselves but also know how to answer questions properly. Geeks are always concerned with different kinds of factual questions, their goal is not to figure out the answer, but rather figure out how to get to the answer. Therefore, it is very important for geeks to write. Also, the programming that they do is also a kind of a way of writing since they reach their goal of solving a problem through writing code.

Geeks need to make algorithms as well, writing algorithms is again another form of writing, it is basically a procedure that they write to solve a problem. Geeks should not only be great at computer related things but also have some knowledge about humanities. They should know about other things rather than just about computer science. Geeks should write so that they can further improve their thinking skills which helps in problem solving. They should be able to talk and write about other things rather than just computer related topics. Writing is an essential thing for geeks, especially those in the programming field since coding is also a form of writing, the only difference is that coding is in a computer language. 

Geeks need to know how to communicate well, they need to know how to convey their ideas or they're point of view to the other team members/programmers. They need to know how to write English correctly or for instance any other language that is used in the country they are in. When writing code they need to explain what the code is doing through comments, and they can only explain correctly and deliver the write details if they know how to express. If they are not in practise they would probably not be able to explain their point properly. This would not only be a plus point for the geek but also for other people who are reading the code. Since geeks also need to write some technical documentation for the end users, they need to know how to write properly otherwise they're code and comments would make no sense to the end user reading that documentation. So the more computer geeks write the better they know about expressing themselves.